函数组合

const add1 = (x) => x + 1
const mul3 = (x) => x * 3
const div2 = (x) => x / 2
//每个函数都要return 进行传参数的
div2(mul3(add1(add1(0)))) // => 3

const compose = (...fns) => {
  return x => fns.reduceRight((v, f) => f(v), x);
}
//调用
compose (add1,mul3,div2)


posted @ 2017-10-12 16:26  风吹麦浪打  阅读(157)  评论(0编辑  收藏  举报