It's pronounced Diane. I do data architecture, operations, and backend development. In my spare time I maintain Massive.js, a data mapper for Node.js and PostgreSQL.
The reduce accumulator doesn't have to be one value -- it's quite useful in places you'd use both filter and map to choose some elements of an array and generate derived values, and you only have to traverse the array once.
Just to summarize:
forEachif you need to act on every item (display all prices)mapsame, but return a new array with the new values (add 10% tax to all prices)filterif you need to remove items (get prices under 10$)includesif you need to know if the array contains at least one (does one prices is exactly equal to 10$)somesame, but you can use a function as assertion (does one price is under 10$)reduceif you need to transform an array into one value (sum all prices)ps: Try to never modify a variable (except iterator).
The
reduceaccumulator doesn't have to be one value -- it's quite useful in places you'd use bothfilterandmapto choose some elements of an array and generate derived values, and you only have to traverse the array once.For large data set I would agree (even tho I never thought of it). But for sub 100 items, the lose in clarity isn't much worth it.