function map(arr, fn) { let newArr = []; for (let i = 0; i < arr.length; i++) { newArr[i] = fn(arr[i], i, arr) } return newArr; } function filter(arr, fn) { let newArr = []; for (let i = 0; i < arr.length; i++) { if (fn(arr[i], i, arr)) { newArr.push(arr[i]); } } return newArr; } var arr=[1,2,3,4,5,6] console.log(map(arr,(item)=>item+1)) console.log(filter(arr,(item)=>item>3))
来源:https://www.cnblogs.com/superlizhao/p/11477511.html
来源:https://www.cnblogs.com/ympjsc/p/12293541.html