3 ms·
The main argument for using reduce is when you really want to accomplish what you're doing in a single expression: - Because you have an un-braced arrow functi
by _bxg1 7y ago
The main argument for using reduce is when you really want to accomplish what you're doing in a single expression:
- Because you have an un-braced arrow function
- Because you want to guarantee* no side-effects
- Because it's in the middle of a React render, or similar
Certain things can only be accomplished in a single expression by using reduce. But I agree that unlike other list-comprehensions it's generally harder to read than the imperative equivalent, outside of simple cases like summing numbers or concatenating arrays.
* Of course you could technically create side-effects from within any of your list-comprehension callbacks; like most things in JavaScript, this is only enforced by convention