/**
* reduce方法
* @param {*} fu 回调函数
* @param {*} initVal 初始值
*/
Array.prototype.myReduce = function(fu, initVal){
let prev = initVal == undefined ? this[0] : initVal;
let i = initVal == undefined ? 1 : 0;
for(; i< this.length; i++){
prev = fu(prev, this[i], i, this)
};
return prev
}
var arr = [1,2,3]
var result = arr.myReduce((prev, curr, index, arr)=>{
return prev + curr
}, 999)
// result ⇒ 1005