js|js 实现reduce、forEach、map

reduce

Array.prototype.myReduce = function(fn,prev) { for(let i = 0; i< this.length; i++){ if(typeof prev === 'undefined') { prev = fn(this[i],this[i+1],i+1,this) ++i; }else{ prev = fn(prev,this[i],i,this) } } return prev }

forEach
Array.prototype.myForEach = function(fn){ for(let i = 0; i

map
Array.prototype.myMap= function(fn){ const arr = [] for(let i = 0; i

    推荐阅读