手写步骤:
1. 先判断参数是否为函数,否则直接返回
2.创建一个新数组用于返回filter后的结果
3.循环遍历数组中每一个值,调用函数,将满足条件的元素放入新数组
4.返回新数组
Array.prototype._filter = function(fn) {
if(typeof fn !== 'function') return
let res = []
for(let i = 0 ; i < this.length ; i++) {
if(fn(this[i])){
res.push(this[i])
}
}
return res
}