As a result, the value of initialValue , a function with two important parameters decreases (may take more) and list values. If there is no initialValue , then he accepted it as the first element of the list. The function should do something with the previousValue , usually used as the accumulator, and nextValue .
So, suppose you have a list of values: [1, 2, 3, 4, 5] and the function should add 2 parameters and initialValue of 0 .
First step:
0 + 1 = 1 2 3 4 5
Second step:
1 + 2 = 3 3 4 5
Third step:
3 + 3 = 6 4 5
Fourth step:
6 + 4 = 10 5
Fifth step:
10 + 5 = 15
As you can see, the input went from list to a single value, hence the name reduce . In your example, there is no initialValue (this is the second argument), so it seems to start in the second step.
source share