Last, but definitely not least, you should pay attention to the general-purpose array transformation that is
.reduce() is slightly different from all the other methods mentioned above, as it uses a higher-order function as its argument, as well as an accumulator. This might sound a little bit confusing at first, so an example should help you grasp the basic idea behind
The above example should not be particularly confusing to anyone who has ever had to sum the values of an array. We first define a reusable higher-order function that we use to sum the values of each array. Then, we actually use this function to sum the values of the first array and then, using the already accumulated value of the first array’s sum as our starting value, we feed this sum to the second array summation function, so that all values in the second array will be added to that, instead of zero.
... read the whole story at hackernoon.com.