DEV Community

Discussion on: Javascript: how to merge multiple objects with sum of values

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Definitely! Your solution demonstrates how Array.reduce would work under the hood for this problem, so it's no "bad" per se.

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt

I think Array.reduce is more like recursive function, rather than taking advantage of mutability.

Thread Thread
 
timhlm profile image
moth

This is right on the money. There’re certain times when mutating things makes sense, and others when generating a new array with reduce is a better choice. It’s all about knowing when to use the right tool.