DEV Community

Discussion on: Stop mutating in map, reduce and forEach

Collapse
 
sebalr profile image
Sebastian Larrieu • Edited

I agree in everything but the reduce.
In my opinion (and based on what I've learned) reduce is about transforming a collection into a single value, that's why its param is called accumulator.
I think your reduce use case is good for performance but not very clear.
I believe such a complex behaviour (filter AND map) should be in a for loop, using reduce for filter and map is as hacky as mutating data in map

Collapse
 
smeijer profile image
Stephan Meijer • Edited

I agree. I messed up that one. 😔 I might rewrite that paragraph to not confuse readers and teach them wrong patterns.

*edit, I updated that section. I hope you don't mind I quoted you.