4 ms·
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 "no
by konsumer 8y 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 https://codepen.io/konsumer/pen/bKKYJO?editors=0010
This can make things very hard to troubleshoot.
- konsumer 8y agoAnd whether it mutates is kind of a surprise. Like reduce doesn't, even though it works similar to forEach, map, and every.
- twiss 8y agoNo, all of them do: https://codepen.io/anon/pen/bKKaBy?editors=0010 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.
- konsumer 8y agoah, yeah, forgot acc param in reduce. updated.