定义:要满足结合律,通过传递不同的函数参数,可以将两两相邻的函数先进行结合,再与第三个函数参数进行结合,对于结果是不会发生改变的

    1. /**
    2. * @desc 函数组合结合律:将两两相邻的函数参数组合执行,再与第三个函数参数组合
    3. * @instemple compose(a, b, c) => compose(compose(a,b), c) => compose(a, compose(b,c))
    4. */
    5. const _ = require('lodash');
    6. // const reverse = arr => arr.reverse();
    7. // const first = arr => arr[0];
    8. // const toUpper = arr => arr.toUpperCase();
    9. // const fn = _.flowRight(toUpper, first, reverse);
    10. // const fn = _.flowRight(_.toUpper, _.first, _.reverse); // 使用lodash提供的方法
    11. // const fn = _.flowRight(_.flowRight(_.toUpper, _.first), _.reverse) // 将部分函数参数先结合-1
    12. const fn = _.flowRight(_.toUpper, _.flowRight(_.first, _.reverse)); // 将部分函数参数先结合-2
    13. console.log(fn(['onw', 'two', 'three']))