Skip to the solution
MediumFrontend5 min read

Implement Promise.allSettled()

738 views

The problem

Problem, as an interviewer would state it: "Implement Promise.allSettled() — unlike Promise.all, it should NEVER reject overall. Every input's real outcome, whether it succeeded or failed, should show up in the results array."

Examples:

Code
await myAllSettled([Promise.resolve(1), Promise.reject("err"), Promise.resolve(3)]);
// [{status:"fulfilled", value:1}, {status:"rejected", reason:"err"}, {status:"fulfilled", value:3}]

Clarifying questions expected:

  • Can this genuinely be built on top of a real, already-implemented Promise.all, or does it need entirely separate machinery?
  • What exact shape should a fulfilled vs. rejected result object have?
  • Does result order still need to match input order, like Promise.all?

Code / implementation expected: Yes — real, direct proof that a mix of fulfilled and rejected inputs produces a correctly-shaped settled-status array, with the overall operation never rejecting.

  • promise
  • promiseAllSettled

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

5 min read · 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, direct proof: Promise.allSettled() genuinely never rejects overall, correctly reporting each input's own real outcome

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 104 of 154 in JavaScript coding

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

Implement deepMerge(target, source) — recursive merge

Continue