AniUI Academy
medium+250 XPPractice

Compose functions right to left

compose(f, g)(x) means f(g(x)): the rightmost function runs first and each result feeds leftwards. It reads backwards at first, but it matches how function application is written by hand, and it is the exact signature Redux uses for applyMiddleware.

Implement compose(...fns). It returns a function that invokes the rightmost function with all of the arguments it received, then passes each result to the next function to the left, and returns the leftmost function's result. Given no functions at all, the returned function returns its first argument unchanged.

What it has to do

  • Apply the functions right to left.
  • Pass every argument to the rightmost function; the rest each receive one value.
  • With no functions, return the first argument unchanged.
  • Work with a single function.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.