Earlier quoted context omitted.
The article obfuscates the point. Reducers/transducers are from the FP world. In FP avoiding mutable state is one the main point. dot = field => obj => obj[field] // unsafe Array.average = self -> reduce(add, self) / self.length // unsafe slang.filter(s -> s.popularity > 0) .map(dot('popularity')) .average() Bonus points: - no state - reusable pure functions - a tad shorter - maybe as readable as the `for over state`…
Downside: Still going over the array multiple times.
You could (usually, but not always) compose the functions you're passing into filter and map and use reduce instead to do both operations in a single pass.
(Edit: This is a big point in the article -- apologies, I hadn't finished reading it yet.)