题解 | #实现Array.filter函数的功能

请补全JavaScript代码,要求实现Array.filter函数的功能且该新函数命名为"_filter"。

http://www.nowcoder.com/practice/93b96e9694634437898353f844d877af

Array.prototype._filter = function (fn){
    if(typeof fn !== "function") return ;
    let arr = [];
    for(let i = 0;i<this.length;i++){
      if(fn(this[i],i,this)){
        arr.push(this[i])
      }
    }
    return arr;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务