Thanks for this simple article on reduce! I have a suggestion for changing the map method to a more performant version. Would love to see an article on rxjs's scan method!
The performance of this map is n^2 because we are returning a new copied array inside the reducer method. Isn't this unnecessary immutability? Because we control the initial empty array state, we could mutate this array inside the reducer and still benefit from mutability for the caller of the map method.
Thanks for this simple article on reduce! I have a suggestion for changing the map method to a more performant version. Would love to see an article on rxjs's scan method!
The performance of this map is n^2 because we are returning a new copied array inside the reducer method. Isn't this unnecessary immutability? Because we control the initial empty array state, we could mutate this array inside the reducer and still benefit from mutability for the caller of the map method.
Instead of this
We could do this -