map
function myMap(arr, callback) {
if(Array.isArray(arr)) {
if(arr.length === 0) return arr;
const brr = [];
for(let item of arr) {
brr.push(callback(item))
}
return brr;
}
}
filter
function myFilter(arr, callback) {
if(Array.isArray(arr)) {
if(arr.length === 0) return [];
const brr = [];
for(let item of arr) {
callback(item)?brr.push(item):''
}
return brr;
}
}
标签:map,arr,return,callback,brr,filter,item,手写
From: https://www.cnblogs.com/taosifan/p/16874549.html