Combine single-argument functions into one chained function
You are tasked with implementing a compose function that combines multiple single-argument functions into a single function. This composite function should apply the given functions in sequence to an initial value, transforming it step by step. A compose function in JavaScript is often built with Array.prototype.reduceRight().
Given three functions a, b, and c, each performing a distinct mathematical operation on an input value, your compose function should enable these functions to be applied in the order they are provided.
Example:
a: Multiplies the input by 4.b: Adds 4 to the input.c: Subtracts 1 from the input.Starting with an initial value of 5, the compose function should return the final result after sequentially applying these functions. Therefore, compose(a, b, c)(5) should yield 23, following these steps:
a to 5: a(5) = 5 * 4 = 20b to 20: b(20) = 20 + 4 = 24c to 24: c(24) = 24 - 1 = 23This example illustrates the transformation process, demonstrating how each function modifies the value passed through the composition.
Your implementation should allow for any number of functions to be composed, providing a flexible and powerful tool for function chaining and value transformation.