SOURCE

function add(n){
    return n+1
}

function mul(n){
    return n*2
}

function minus(n){
    return n-1
}

function divi(n){
    return n/2
}

console.log(divi(minus(mul(add(3)))))

console.log(pipe(divi,minus,mul,add)(3))

//递归
// function compose(...funcs){
//     let count = funcs.length,result;
//     return function fn(x){
//         if(count < 0) return result;
//         result = funcs[count](x)
//         return fn(result)
//     }
// }

//reduceright
function compose(...funcs){
    return function fn(x){
        return funcs.reduceRight((res, cb) => cb(res), x);
    }
}

//pipe
function pipe(...funcs){
    return function(x){
        return funcs.reduce((res,cb) => cb(res), x)
    }
}
console 命令行工具 X clear

                    
>
console