Problem, as an interviewer would state it:
"Implement Promise.all() yourself. Given an array of promises, return a single promise that resolves with an array of all their results — in the ORIGINAL input order, even if they finish in a different real order — and rejects immediately if any one of them rejects."
Examples:
await myPromiseAll([slowPromise, fastPromise]);
// [slowResult, fastResult] - original order, even though fast finished first
Clarifying questions expected:
- Does "fail fast" mean reject the moment the FIRST rejection happens, even while other promises are still pending?
- Should a plain, non-promise value in the array be handled, or is every element guaranteed to already be a real promise?
- What should happen with an empty input array?
Code / implementation expected: Yes — real, direct proof that results preserve original input order regardless of real completion order, and that a rejection genuinely short-circuits immediately.