Skip to main content

2629. Function Composition

https://leetcode.com/problems/function-composition

Javascript

var compose = function(functions) {
return function(x) {
let curr = x
while (functions.length > 0) {
curr = functions.pop()(curr)
}
return curr
}
};

Typescript

type F = (x: number) => number;

function compose(functions: F[]): F {
return function(x) {
let curr = x
while (functions.length > 0) {
curr = functions.pop()(curr)
}
return curr
}
};