AniUI Academy
medium+250 XPPractice

Pipe functions left to right

pipe(f, g)(x) means g(f(x)). Same machinery as compose, opposite direction, and far easier to read for a data transformation: trim, then split, then count.

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

What it has to do

  • Apply the functions left to right.
  • Pass every argument to the leftmost function; the rest each receive one value.
  • With no functions, return the first argument unchanged.
  • Support a chain of more than two functions whose types change along the way.

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.