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

posted on 2021-10-13 18:01  码农-编程小子  阅读(266)  评论(0编辑  收藏  举报