function map(f, a) {
var result = []; // 创建一个数组
var i; // 声明一个值,用来循环
for (i = 0; i != a.length; i++)
result[i] = f(a[i]);
return result;
}
var f = function(x) {
return x * x * x;
}
var numbers = [0,1, 2, 5,10];
var cube = map(f,numbers);
console.log(cube);
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Functions
网友评论