Array.prototype.customReduce = function(fn , prev) {
for(let i = 0; i<this.length; i++) {
if (typeof prev === 'undefined') {
// prev不存在
prev = fn(this[i], this[i+1], i+1, this);
i++;
} else {
prev = fn(prev, this[i], i, this);
}
}
return prev;
}
复制代码
【web前端】自己实现Array.reduce()
最新推荐文章于 2024-05-09 13:10:39 发布