函数组合:如果一个函数要经过多个函数处理才能得到最终的值,这个时候可以把中间过程的函数合并成一个函数
函数组合默认是从右到左执行
const _ = require("lodash")
const reverse = arr => arr.reverse();
const firstt = arr => arr[0];
const toUpper = s => s.toUpperCase();
const f = _.flowRight(toUpper,firstt,reverse);
console.log(f(["one","two","three"])); // THREE
const _ = require("lodash")
const reverse = arr => arr.reverse();
const firstt = arr => arr[0];
const toUpper = s => s.toUpperCase();
// 重写 flowReght 取名compose
// function compose(...args){
// return function(value){
// return args.reverse().reduce(function(acc,fn){
// return fn(acc)
// },value)
// }
// }
// 重写 ES6
const compose = (...args) => value => args.reverse().reduce((acc,fn)=>fn(acc),value)
// const f = _.flowRight(toUpper,firstt,reverse);
const f = compose(toUpper,firstt,reverse);
console.log(f(["one","two","three"])); //THREE