Day 9: compose function

Dharan Ganesan - Jul 20 '23 - - Dev Community

Question

Write a function called compose that accepts multiple functions as arguments and returns a new function. The new function should apply the input functions in reverse order, passing the result of each function call as an argument to the next.

function double(x) {
  return x * 2;
}

function square(x) {
  return x * x;
}

function increment(x) {
  return x + 1;
}

const composedFunction = compose(increment, square, double);
const result = composedFunction(10); // Result: 401
Enter fullscreen mode Exit fullscreen mode

🤫 Check the comment below to see answer.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player