promise.any( )
Problem statement
Implement customPromiseAny(promises), a version of Promise.any.
It should resolve with the first fulfilled value. It should reject only when every input rejects.
How to approach promise.any( )
The strategy an interviewer expects you to reach for.
Promise.any is “first success wins” — useful when any mirror can answer, and only total failure is fatal. Naive move Copy Promise.race. Then the first rejection wins and a later success is ignored — the opposite of what any means. Where it breaks You must ignore rejections until every input has rejected, then throw AggregateError with all reasons. Empty input rejects immediately. The first fulfillment resolves and later results are ignored. The fix Track rejection count and an errors array by index. On fulfill → resolve once. On reject → store reason; when rejectedCount === length, reject with AggregateError. Remember: any ignores failures until none are left; race does not. Say this in the interview: I'd resolve on the first fulfillment, collect every rejection, and only AggregateError when the entire input set has failed — including the empty-array edge.
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.