How can I have a JavaScript function let's say piper()
which takes several functions as its arguments and it returns a new function that will pass its argument to the first function, then pass the result to the second, then
pass the result of the second to the third, and so on, finally returning the output of the last function.
Something like piper(foo, fee, faa)(10, 20, 30)
would be equivalent to calling faa(fee(foo(10,20,30)))
.
ps: It was a part of an interview, that I did few days ago.