You filter every single value and then you map the remaining values. } document.write("Subtraction of array elements are=>" /* calling getAddition function from reduce function and displaying sum*/ So what's the big deal, you ask? + arrayElements.reduce(getSubtraction)); Because the pipeline is an array, it can be easily modified. If you’re trying to tally up fruit, and you leave out the initial value then things get weird. So I wrote a previous article about the many other things you can do with reduce that don’t involve arithmetic. arrayElements.reduce( functionName(total, presentValue, presentIndex, actualArray), intialArrayValue); Explanation: functionName(total, presentValue, presentIndex, actualArrayObject), This function contains 4 arguments, they are explained below. When there are no more numbers left in the array the method returns the total value. The reduce function stays exactly the same. Since we know about the state being a immutable data structure, we can use the JavaScript spread operator to create a new state object from the incoming state and the part we want to change (e.g.