const afn = function(a) {
return a*2
}
const bfn = function(b) {
return b+3
}
const pipe = function(...fns) {
return function(val) {
return fns.reduce((total, fn) => {
return fn(total)
}, val)
}
}
const compose = function(...fns) {
return function(val) {
return fns.reverse().reduce((total, fn) => {
return fn(total)
}, val)
}
}
const myFn = pipe(bfn,afn)
const myFnCompose = pipe(bfn,afn)
console.log(myFn(2))// 10
console.log(myFnCompose(2))// 7
偶数
