Implement Promise.any
Implement promiseAny(promises), which behaves like Promise.any for an array, without calling it. Promise.all, allSettled, race and any are switched off while it runs.
- Resolve with the value of the first input to fulfil, however many others have already rejected.
- Reject only once every input has rejected, with an
AggregateErrorwhoseerrorsarray holds the reasons in input order (its message may be anything). - Accept plain values beside promises.
- An empty input rejects at once, with an
AggregateErrorwhoseerrorsis[].
Everything runs on a virtual clock, so the grader sees exactly when the result settles.
Hints
Hint 1
Promise.all inverted: pass resolve straight through as the fulfilment handler, and do the counting in the rejection handler.
Hint 2
Store each reason at its input's index, not in arrival order, so the errors array reads like the input did.
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.