1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env node /** * @param {Function[]} functions * @return {Function} */ var compose = function (functions) { return function (x) { var result = x; for (var i = functions.length - 1; i >= 0; i--) { result = functions[i](result); } return result; }; }; const fn = compose([(x) => x + 1, (x) => 2 * x]); console.log(fn(4)); // 9