arr.reduce(callback, [initialValue])
callback
Function to execute on each element in the array, taking four arguments:
accumulator 累加器
The accumulator accumulates the callback's return values; it is the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied (see below).
currentValue 当前值
The current element being processed in the array.
currentIndex
The index of the current element being processed in the array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
array 当前数组
The array reduce was called upon.
initialValue
累加器初始值,
如果不存在则accumulator为第一个元素值,currentValue为第二个元素值 currentIndex从1开始
如果存在则accumulator为初始值,currentValue为第一个元素值 currentIndex从0开始
[Optional] Value to use as the first argument to the first call of the callback. If no initial value is supplied, the first element in the array will be used. Calling reduce on an empty array without an initial value is an error.
Return value
The value that results from the reduction.