Build a new function by applying a list of functions in sequence to an input value.
Compose Functions
gfgYou are given an array of functions. Create and return a new function that, when called with one argument, passes that argument through the functions from right to left.
In other words, if the functions are , the composed function should behave like:
If the array of functions is empty, the returned function should behave like the identity function and return its input unchanged.
This problem focuses on understanding function chaining and evaluating a composed pipeline in the correct order.
functions, where each function takes one argument.x when the returned function is invoked.Return a function that applies the given functions from right to left and produces the final result.
Example 1
Input
functions = [x => x + 1, x => x * 2, x => x - 3], x = 4
Output
3
Explanation
Apply the functions from right to left: first x - 3 gives 1, then x * 2 gives 2, then x + 1 gives 3.
Example 2
Input
functions = [], x = 10
Output
10
Explanation
With no functions to compose, the returned function acts like the identity function.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.