Implement Promise.any

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Implement Promise.any

Approach

Resolve with the first fulfilled promise value, ignoring rejections until all have failed. Track rejected count and store errors by index. Only reject with an AggregateError when every promise has rejected.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Promise Combinator

Why It Works

The first fulfillment short-circuits to resolve the outer promise, while rejections are silently collected. Only when all promises reject does the aggregate error surface.

Updated Feb 2026