blob: 67e8ff7acfa1fa9aecffbe04c430db121bed76ea (
plain) (
tree)
|
|
#!/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
|