Implement Promise.allSettled

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.allSettled

Approach

Return a new Promise that never rejects early. For each input promise, attach both a then and catch handler that record the outcome as a {status, value} or {status, reason} object at the correct index. Use a counter to resolve the outer promise once all have settled.

Complexity Analysis

Time
O(n)
Space
O(n)

Pattern

Promise Combinator

Why It Works

By catching rejections locally and converting them into result objects, no single rejection can short-circuit the aggregation, guaranteeing all outcomes are collected.

Updated Mar 2026