composeAsync
Problem statement
Implement composeAsync(...fns), which combines async or sync functions into one function.
Composition runs from right to left: composeAsync(f, g)(x) should behave like await f(await g(x)).
How to approach composeAsync
The strategy an interviewer expects you to reach for.
Async compose is a pipeline: run functions right-to-left, awaiting each hop — the async cousin of compose / reducer pipelines. Naive move Fire every function with Promise.all or walk left-to-right. Order and dependencies break. Where it breaks Each stage needs the previous resolved value. A rejection should stop the pipeline. Zero functions should return the input (identity). The fix Return an async function. Start from the seed value; iterate from the last fn to the first, awaiting each. That is right-to-left composition. Remember: Right-to-left, await each step — not parallel. Say this in the interview: I'd return an async function that folds the seed through the functions from right to left, awaiting every stage so failures short-circuit.
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Runnable editor with the hidden test suite
- Progressive hints that unlock as you get stuck
- Senior-level reference solution with a line-by-line walkthrough
Already a member? Log in to open the workspace.