1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| function double(n) { return n * 2; }
let arr = [1, 2, 3]; let newArr = arr.map(double); // console.log(newArr);
// function map (arr, fn) {} function map (arr, callback) { let result = []; for(let i = 0; i < arr.length; i++) { // result[i] = arr[i] result[i] = callback(arr[i]); } return result; }
console.log(map([1,2,3], double))
|