Open Guyidingsanyu opened 2 years ago
// find实现
Array.prototype._find = function(callback) {
let currentVal
for(let i = 0; i < this.length; i++) {
if (callback(this[i])){
currentVal = this[i]
break
}
}
return currentVal
}
let res = [1, 2, 3]._find(item => item > 2)
console.log(res)