// Define the callback function.
function addRounded (previousValue, currentValue) {
return previousValue + Math.round(currentValue);
}
// Create an array.
var numbers = [10.9, 15.4, 0.5];
// Call the reduce method, starting with an initial value of 0.
var result = numbers.reduce(addRounded);
document.write (result);
reduce一般的我们用的时候只会用到前面的callback,但是其实像上面的代码一样,它还可以接受一个叫initValue的值,如果你传进去了这个值,那默认第一次就是从这个initValue和数组的第一个值的比较了。