Problem, as an interviewer would state it:
"Implement Promise.race() yourself. Given an array of promises, return a new promise that settles — resolves OR rejects — the moment the FIRST input promise settles, matching whatever that promise did."
Examples:
const fast = new Promise(r => setTimeout(() => r("fast"), 20));
const slow = new Promise(r => setTimeout(() => r("slow"), 100));
await Promise.race([slow, fast]); // "fast" - it settled first
Clarifying questions expected:
- Does "first" mean first to RESOLVE specifically, or first to SETTLE at all (resolve OR reject)?
- Can the input array contain non-promise values (plain values)?
- What happens with an empty input array?
Code / implementation expected: Yes — real, direct proof that both a fast resolution and, separately, a fast rejection each correctly win a real race against a slower opposite outcome.