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