const reverse = arr => arr.reverse();
const first = arr => arr[0];
const toUpper = s => s.toUpperCase();
// ES5 写法
function compose (...args) {
return function (value) {
return args.reverse().reduce(function (acc, fn) {
return fn(acc)
}, value)
}
}
const f = compose(toUpper, first, reverse);
console.log(f(['one', 'two', 'three'])); // THREE
// ES6 写法
const comost = (...args) => value => args.reverse().reduce((acc, fn) => fn(acc), value)
const f = compose(toUpper, first, reverse);
console.log(f(['one', 'two', 'three'])); // THREE