DEV Community

Discussion on: Sorting an array into groups with reduce

Collapse
 
jacobmparis profile image
Jacob Paris

The accumulator used in a reduce function is a temporary variable created by the reduce function. The only scope that has access to it is the current iteration of reduce, so creating a new variable each time is unnecessary.

If we were to mutate the addresses argument, we would run into the problems you're hinting at so that indeed is bad practice, but none of those issues exist with the reduce-accumulator.