函数的合成

1.函数的合成

合成两个函数
const compose = function (f, g) {
return function (x) {
return f(g(x));
};
}

const compose=(arr)=>{
return function(x){
return arr.reduce((f,g)=>{
return g(f(x))
})
}
}

const fx=(s)=>{return s+'-X'}

const fy=(s)=>{return s+'-Y'}

compose([fx,fy])('jeff')


2.柯里化

function addX(y) {
return function (x) {
return x + y;
};
}

人生旅途,边走边看...
原文地址:https://www.cnblogs.com/dming4/p/15403361.html