定义:要满足结合律,通过传递不同的函数参数,可以将两两相邻的函数先进行结合,再与第三个函数参数进行结合,对于结果是不会发生改变的
/*** @desc 函数组合结合律:将两两相邻的函数参数组合执行,再与第三个函数参数组合* @instemple compose(a, b, c) => compose(compose(a,b), c) => compose(a, compose(b,c))*/const _ = require('lodash');// const reverse = arr => arr.reverse();// const first = arr => arr[0];// const toUpper = arr => arr.toUpperCase();// const fn = _.flowRight(toUpper, first, reverse);// const fn = _.flowRight(_.toUpper, _.first, _.reverse); // 使用lodash提供的方法// const fn = _.flowRight(_.flowRight(_.toUpper, _.first), _.reverse) // 将部分函数参数先结合-1const fn = _.flowRight(_.toUpper, _.flowRight(_.first, _.reverse)); // 将部分函数参数先结合-2console.log(fn(['onw', 'two', 'three']))
