2025-08-20 20:36:18 +0300 MSK
Function Composition
Links
Code
/**
* @param {Function[]} functions
* @return {Function}
*/
var compose = function(functions) {
if (functions.length === 0) {
return function(x) { return x; };
}
return functions.reduceRight(function(prevFn, nextFn) {
return function(x) {
return nextFn(prevFn(x));
};
});
};