Skip to content

2629. Function Composition 👍

1
2
3
4
5
6
7
type F = (x: number) => number;

function compose(functions: F[]): F {
  return function (x) {
    return functions.reduceRight((val, f) => f(val), x);
  };
}