DEV Community

Discussion on: 5 Anti-Patterns to Avoid When Working With Collections in JavaScript

Collapse
 
blindfish3 profile image
Ben Calder • Edited

In section 1 you say:

Most developers especially those who are more into functional programming may find this to be clean, concise and performant at its best

I'm curious to know how many advocates of FP would write an add function in that way; where you use a callback to act on the result. You'd normally just return the result directly and avoid things that might cause unexpected side-effects (such as callback functions).

Also the uncondensed version is subject to the same bug:

numbers.forEach(function(nums, callback) {

The problem you demonstrate is that you need to be familiar with the argument signature passed from Array iteration functions. It's true that passing a function name means you may be less likely to spot the issue; but in my experience it's also rare to not write the function inline anyway.