The reduce function
The reduce function is another high-order array method that accepts two parameters. The purpose of this function is to convert or reduce an array into a single value.
For example when you want to grab the sum of the numbers an array holds. As the picture above shows, you need to specify two parameters, The first is the function that is going to make the reduce, and the second one is the starting point where the reduce is going to use as a point of begin.
Then the callback function accepts two arguments, the first argument (in this case a) represents the summary (at the beginning is 0, then it is updated with the value of each return statement after every iteration). The second argument represents each one of the array's entries (or values etc).
To understand this better, let's try to take a look at every iteration of this reduce function and see how it works.
First iteration: a = 0; b = 0. So the result of (a + b) = 0, that means that next iteration a = 0.
Second iteration: a = 0; b = 1. So a = 1 for the next iteration.
Third iteration: a = 1; b = 2; So a = 3 for the next iteration.
Fourth iteration: a = 3; b = 5; So a = 8 now.
Fifth iteration: a = 8; b = 7; So a = 15 now.
Last iteration a = 15, b = 3. So the result that comes after the reduce is 18.