logoalt Hacker News

jakub_gyesterday at 9:45 PM1 replyview on HN

I dislike reduce because people sometimes do wild things in the callback that take a lot of mental effort to understand.

Sometimes people abuse .map as well to do things that are not obvious (i.e. instead of mapping elements of an array to another array, they modify global variables in a for-loop fashion, and discard the result).

But reduce is abused more often and you always need to think really hard if e.g. the initial accumulator is passed or not (it's optional in some languages!), if a correct one is passed (when a compound type is used) and so on.


Replies

Terr_yesterday at 10:37 PM

> sometimes do wild things in the callback that take a lot of mental effort to understand

And even when they don't, you have to spend effort to determine that they aren't.