Pattern: Function with too many parameters
Issue: -
Functions with numerous parameters are difficult to understand and use, as they require memorizing each parameter's type, purpose, and order. Large parameter lists often indicate that a function is doing too much or that its parameters should be refactored into an options object.
Example of incorrect code:
function foo(bar, baz, qux, qxx) {
doSomething();
}
const process = (title, firstName, lastName, age, city, state, country) => {
// ...
};
Example of correct code:
function foo(bar, baz) {
doSomething();
}
const process = (userInfo) => {
const { title, firstName, lastName, age, address } = userInfo;
// ...
};