Implement Promise.race

Easy
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.race

Approach

Wrap all promises in a new Promise and attach resolve/reject handlers to each one. The first promise to settle (fulfill or reject) triggers the outer promise, making it a race to the finish.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Promise Combinator

Why It Works

Since Promise.resolve/reject can only be called once, the first promise to settle wins and all subsequent settlements are ignored.

Updated Mar 2026