Function composition is a mathematical operation that combines two or more functions in such a way that the output of one function becomes the input for the next function. The result is a new function that combines the behavior of both functions.
Implementation of general composition function
The corresponding execution order is from left to right. If you want to execute from right to left, then you can use the Array.prototype.reduceRight method.