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;
};
}