To balance all the negative comments about readability, I do think .reduce is often more readable than its traditional alternatives.
Simply because its use cases are always the same so you can guess the code without reading it:
* Reducing an array of numbers, with a number as initial value? => We are going to do some operations on those numbers.
* Reducing an array of objects, with a number as initial value? => We are going to do some operations on one or several props of those objects.
* Reducing an array of objects, with an empty object as initial value? => We are going to create a key/value object with computed key names.
Then just by reading the name of the variable on the left of the assignment, you know exactly what's going on.
And if you don't need to know about the details, you can just jump to the next statement.
const products = [product1, product2, product3]
const sumPrices = products.reduce(/* I don't need to read this */, 0)
const users = [users1, users2, users3]
const usersByFirstname = users.reduce(/* I don't need to read this */, {})
const usersByLastname = users.reduce(/* I don't need to read this */, {})
Simply because its use cases are always the same so you can guess the code without reading it:
* Reducing an array of numbers, with a number as initial value? => We are going to do some operations on those numbers.
* Reducing an array of objects, with a number as initial value? => We are going to do some operations on one or several props of those objects.
* Reducing an array of objects, with an empty object as initial value? => We are going to create a key/value object with computed key names.
Then just by reading the name of the variable on the left of the assignment, you know exactly what's going on.
And if you don't need to know about the details, you can just jump to the next statement.