lodash 库 提供了组合函数的方法:
- flow() 从左往右执行
- flowRight() 从右往左执行,使用的更多一些
// 使用lodash 的 组合函数
const _ = require('lodash');
// 求数组的最后一项,并转换成大写
const first = arr => arr[0] ;
const reverse = arr => arr.reverse();
const toUpper = str => str.toUpperCase();
const fnRight = _.flowRight(toUpper,first,reverse);
const fn = _.flow(reverse , first, toUpper);
console.log(fnRight(['one','two','three']));
console.log(fn(['one','two','three']));