JavaScript Async

Implement Promise.allSettled

mediumJS SpecificJS / TS5 tests

Problem Statement

Write an implementation of `promiseAllSettled(promises)` that returns a promise resolving after all given promises have either fulfilled or rejected. The returned promise resolves to an array of outcome objects matching the order of the input array: - For fulfilled promises: `{ status: "fulfilled", value: <value> }` - For rejected promises: `{ status: "rejected", reason: <reason> }` Non-promise values in the input array should be treated as already fulfilled promises. An empty input array should resolve immediately to an empty array.

Examples

Example 1:
Input: [Promise.resolve(1), Promise.reject("error")]
Output: [{ status: "fulfilled", value: 1 }, { status: "rejected", reason: "error" }]

Example 2:
Input: [Promise.resolve(42), "immediate"]
Output: [{ status: "fulfilled", value: 42 }, { status: "fulfilled", value: "immediate" }]
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

5 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.