Pattern: Array method on arguments
Issue: -
The arguments object is array-like but not an actual array. Array methods like map, reduce, or filter cannot be called directly on arguments. Convert arguments to an array first.
Example of incorrect code:
function sum() {
return arguments.filter(x => x > 0)
.reduce((a, b) => a + b);
}
Example of correct code:
function sum() {
const args = Array.from(arguments);
return args.filter(x => x > 0)
.reduce((a, b) => a + b);
}