Skip to content

2629-function-composition

DevGod
DevGod
Vtuber
/**
* @param {Function[]} functions
* @return {Function}
*/
var compose = function(functions) {
return function(x) {
functions.reverse();
for(fn of functions){
x = fn(x);
}
return x;
}
};
/**
* const fn = compose([x => x + 1, x => 2 * x])
* fn(4) // 9
*/