promise.all( )
Problem statement
Implement customPromiseAll(promises), a version of Promise.all.
It should resolve when every item resolves, preserve input order, and reject as soon as any item rejects.
How to approach promise.all( )
The strategy an interviewer expects you to reach for.
Interviewers ask for Promise. all when they want to see if you understand ordered fan-in: many async jobs, one result array that keeps input order. Naive move Push into an array as each promise resolves. Race the network: slower items finish later and scramble the order. Where it breaks Empty input must resolve to [] immediately. One rejection must reject the outer promise right away — do not wait for the rest. Non-thenables must still be accepted (wrap with Promise. resolve). The fix Create one outer promise. For each index, settle that input and write results[index] = value. Count successes; when the count hits length, resolve. On first reject, reject once and ignore later settlements. Remember: Index the results; never push. Reject-fast, order-preserving. Say this in the interview: I'd wrap each input in Promise.
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.