← Back to context

Comment by cerved

4 years ago

loops are harder to read. What does it do, map, reduce, send emails to grandma?

In JavaScript, the reduce callback is created once and called repeatedly. For loops are pretty much always the fastest possible way because they use mutable state. They are also a really good way of creating unreadable spaghetti that does things you don't want them to.

I'm not sure what you mean by nested reduces. Chained reduce functions are easy to follow

You can send email to grandma from both map and reduce.

  • The point was that in map and reduce it's clear what's being done and what's being returned, especially in a typed language. Ideally you're also in an environment that doesn't allow for side effects, in which case, grandma gets no emails from map or reduce

    • It is not visible what is returned or what is input im case of chaining. Because return and input parameters are not directly visible and you have to read all previous calls to figure that out.

      And they both trivially allow for side effects.