Loading homepage
Implement compose(...functions), a utility that combines synchronous, single-argument functions into one reusable function.
The returned function takes an input value and applies the supplied functions from right to left. For example, compose(f, g, h)(value) produces f(g(h(value))).
This is useful for building small transformations into a larger operation, such as trimming text, splitting it into words, and counting those words.
Input: const addOne = (value) => value + 1; const double = (value) => value * 2; compose(addOne, double)(3); Output: 7
Input: const square = (value) => value * value; const subtractOne = (value) => value - 1; compose(square, subtractOne)(4); Output: 9
Input: compose()(42); Output: 42
Input: compose( (words) => words.length, (text) => text.split(" "), (text) => text.trim(), )(" red green blue "); Output: 3
compose(...functions) returns a function that accepts one value. Each callback receives the previous callback's result, starting at the rightmost callback. The final result can be any value.