题解 | #实现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;
}