Array#reduce() can often make code less readable and sometimes also slower. A for-of loop is usually a better choice.
See this Twitter thread: https://twitter.com/sophiebits/status/1099014182261776384?s=21
Not sure how strict we should/can be, but my thinking is that we only allow Array#reduce() when the callback returns a number and the initialValue is a number if set.
I don't necessarily agree with this.
The reduce function is a boundary. Mutating the accumulator within that boundary is fine from a purity standpoint, as long as the initialValue isn't a variable reference.
arr.reduce((acc, value) => {
acc[calcdKey] = value;
return acc;
}, {});
The thing I'd lint would be:
Ensuring that the initial value is not a variable reference (unless the variable's type is number | string | boolean).
Most helpful comment
I don't necessarily agree with this.
The reduce function is a boundary. Mutating the accumulator within that boundary is fine from a purity standpoint, as long as the initialValue isn't a variable reference.
The thing I'd lint would be:
Ensuring that the initial value is not a variable reference (unless the variable's type is
number | string | boolean).