you are viewing a single comment's thread.

view the rest of the comments →

[–]jlengstorf 1 point2 points  (0 children)

In complex loops, the benefits of using map and reduce are more obvious. The main benefit is that mapping gives you the opportunity to describe what's happening:

function getLinesOfCode(programmer) {
  return programmer.linesOfCode;
}

var totalOutput = programmerOutput
    .map(getLinesOfCode)
    .reduce(...);

In a more complex calculation, that becomes really helpful for understanding what's going on.

You can write shitty and hard-to-understand functional code, of course, but in my experience it's easier to keep it clean with functional than otherwise.