1.reduce
reduce详解传送门
Array.prototype.myReduce = function(fn, initValue) {
if (initValue === undefined && !this.length) {
throw new Error('myReduce of empty Array with no initial value')
}
let result = initValue ? initValue : this[0]
for (let i = initValue ? 0 : 1; i < this.length; i++) {
result = fn(result, this[i], i, this)
}
return result
}