Problem, as an interviewer would state it:
"Write promiseRetry(fn, retries, delayMs) — it calls fn, and if it rejects, waits and tries again, up to retries additional times, doubling the delay each time (exponential backoff)."
Examples:
await promiseRetry(flakyFn, 3, 100); // retries up to 3 more times, delays 100/200/400ms
Clarifying questions expected:
- Does
retriesmean total attempts, or additional attempts AFTER the first real try? - Should the delay genuinely double each time (exponential), or is a fixed delay acceptable?
- Is there a maximum total delay/timeout across all retries combined, or unbounded?
Code / implementation expected: Yes — real, direct proof of both outcomes: a function that fails its first 2 attempts then succeeds, and a function that genuinely always fails, exhausting all real retries before throwing.