Array#reduce()
and Array#reduceRight()
usually result in hard-to-read code. In almost every case, it can be replaced by .map
, .filter
, or a for-of
loop. It's only somewhat useful in the rare case of summing up numbers.
Use eslint-disable
comment if you really need to use it.
This rule is not fixable.
array.reduce(reducer, initialValue);
array.reduceRight(reducer, initialValue);
array.reduce(reducer);
[].reduce.call(array, reducer);
[].reduce.apply(array, [reducer, initialValue]);
Array.prototype.reduce.call(array, reducer);
// eslint-disable-next-line unicorn/no-array-reduce
array.reduce(reducer, initialValue);
let result = initialValue;
for (const element of array) {
result += element;
}