我已經嘗試了許多方法來獲取父參數是在減少的回調函數可見,但我一定是失去了一些東西......與高階回調參數減少
// 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