reduce
Array.prototype.myReduce = function(fn,initValue){
if(this.length == 0){
throw new Error('Reduce of empty array with no initial value')
}
let i,total;
if(initValue !== undefined){
total = initValue
i = 0;
}else{
total = this[0]
i = 1;
}
for(;i < this.length;i++){
let item = this[i]
total = fn(total,item,i,this)
}
return total
}
有初始值,下表从0开始;无初始值,下标从1开始。
以自己现在的努力程度,还没有资格和别人拼天赋

浙公网安备 33010602011771号