我已经尝试了许多方法来获取父参数是在减少的回调函数可见,但我一定是失去了一些东西......与高阶回调参数减少
// Static
var y = [0, 1, 2, 3, 4, 5, 6, 7].reduce(
function(arr, x){
arr.push(Math.pow(2, x));
return arr},[]);
console.log(y);
// Dynamic
var lambda = function(arr, func) {
return (function(f) { return arr.reduce(function(a, x) {
a.push(f(x));
return a;
}, [])})(func);
}
var y = lambda([0, 1, 2, 3, 4, 5, 6, 7],function(x){return Math.pow(x);});
console.log(y);
输出:
[1, 2, 4, 8, 16, 32, 64, 128]
[NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]
你说的'父parameter'是什么意思? – thefourtheye
我想通过'func'对reduce函数进行显示。 –
你是不是在'Math.pow(x)'中缺少'2'? – thefourtheye