What are some good scenarios in which to use reduce()? I've used map() and filter() quite a bit but I don't use reduce(), mainly b/c I'm not exactly sure what the niche/benefits of the reduce() function are.
Asked
Active
Viewed 91 times
-3
-
when you can do something in one step instead of multiple. Sometimes you need to map all the values, but you do not want X. You can do it with map and filter, or you can just use reduce. – epascarello Feb 27 '19 at 19:28
-
1Possible duplicate of [JavaScript - examples of reduce() function](https://stackoverflow.com/questions/34600900/javascript-examples-of-reduce-function) and [What does the Reduce() JavaScript function do?](https://stackoverflow.com/questions/33392307) and [Is there any real benefit for using javascript Array reduce() method?](https://stackoverflow.com/questions/9629431) – adiga Feb 27 '19 at 19:29
1 Answers
0
Mainly, every scenario where you have to (ha!) reduce the initial array to one single element, while the other methods might also return an array whose length could be greater than 1

Davide Vitali
- 1,017
- 8
- 24