Freelancer, Full-stack developer (React.js / React Native / TypeScript / Node.js). I've come to specialize in developing Dashboards, Administrative Panels, CRM systems, and similar apps.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good point! Thanks!
But I think it's good to have different solutions of the same problem;)
Definitely! Your solution demonstrates how Array.reduce would work under the hood for this problem, so it's no "bad" per se.
I think
Array.reduce
is more like recursive function, rather than taking advantage of mutability.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.