碎片时间学编程「362]:从左到右执行组合反向撰写功能

执行从左到右的函数组合。
使用 Array.prototype.reduce() 执行从左到右的函数组合。
第一个(最左边)函数可以接受一个或多个参数;
其余函数必须是一元函数。
const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
示例:
const add = (x, y) => x + y;const square = x => x * x;const addAndSquare = composeRight(add, square);addAndSquare(1, 2); // 9
更多内容请访问我的网站:https://www.icoderoad.com