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
推荐阅读
- 一个人的碎碎念
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- Shell-Bash变量与运算符
- 清明,是追思、是传承、是感恩。
- 牛人进化+|牛人进化+ 按自己的意愿过一生
- 七老修复好敏感、角质层薄、红血丝
- 华为旁!大社区、地铁新盘,佳兆业城市广场五期!
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- MybatisPlus使用queryWrapper如何实现复杂查询
- python学习之|python学习之 实现QQ自动发送消息