Day 9: compose function

1 min read ❤️ 0 · 💬 1
#day9 #100daysofcode #javascript

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.


Originally published on DEV Community . Read the discussion and share your thoughts there.

© 2026

LinkedIn 𝕏 GitHub