Hacker News new | ask | show | jobs
by konsumer 2920 days ago
It should be noted that you can still mutate in these. Like it's not at all recommended, but you have access to the original array in many of the functional "non-mutating" Array methods, for example: https://codepen.io/konsumer/pen/bKKYJO?editors=0010

This can make things very hard to troubleshoot.

1 comments

And whether it mutates is kind of a surprise. Like reduce doesn't, even though it works similar to forEach, map, and every.
No, all of them do: https://codepen.io/anon/pen/bKKaBy?editors=0010

All of these pass the original array as the last argument, reduce()'s callback just takes one more argument, hence the confusion in the original codepen. It would indeed be highly surprising if some of these functions passed a copy of the original array.

ah, yeah, forgot acc param in reduce. updated.