Thanks for sharing this article, I've always wanted to understand the reduce method.
I find example 2 and 5 hard to understand though. If you could explain it that'll be great. Thanks.
Absolutely.
In the second example, the value will be compared to the accumulator to find the maximum number in the array. The concept behind it works similar to example 1, in regards to how the accumulator and the value/currentValue work.
For the fifth example, when we pass in the current value (color) of let's say, the color green, we will add it up to the accumulator and count it as the first instance. The current value will then move on to the next array element, which is blue, and do the same. If by any chance we find another instance of the color green existing in the color array, we will add it up to the accumulator, which already has an existing instance of the color green, and thus if we return the accumulator, we will find that green has two instances in the color array.
Favourite Jome
QA Engineer @bug0
Thanks for sharing this article, I've always wanted to understand the reduce method.
I find example 2 and 5 hard to understand though. If you could explain it that'll be great. Thanks.