AniUI Academy

Implement Promise.allSettled from scratch

mediumAsync & Promises+250 XPPractice

When you save six form sections at once, Promise.all throws away five results the moment one fails. allSettled waits for all of them and describes each outcome so the UI can mark exactly which section needs attention.

Implement allSettled(promises) without using Promise.allSettled. It resolves with an array in input order, one entry per input. A fulfilled input produces an object with exactly two properties, status: "fulfilled" and value. A rejected input produces an object with exactly two properties, status: "rejected" and reason. Non-promise entries count as fulfilled. The returned promise never rejects, and an empty array resolves with an empty array.

What it has to do

  • Resolve with one entry per input, in input order.
  • Use exactly the keys status and value for a fulfilled entry.
  • Use exactly the keys status and reason for a rejected entry.
  • Never reject, even when every input rejects.
  • Resolve with [] for an empty array.

Where it's been asked

  • Google
  • Amazon

From public interview reports — a problem very like this one has shown up in a round at these companies. Not an exhaustive list.

Stuck? The javascript course covers everything this challenge needs.

Try it yourself
Loading playground...

Ready to check it?

4 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

Need a nudge?

Reveal a conceptual hint or the reference solution. Both were written and reviewed with the problem — no runtime magic.

Discussion

Sign in to post
Sign in to join the conversation.Sign in

No comments yet. Be the first to say something.