Async & Promises

Retry Promise with Max Attempts

mediumJS SpecificJS / TS3 tests

Problem Statement

Implement a `retry(fn, retries, delay)` helper that repeatedly executes an async operation `fn` until it succeeds or exhausts `retries` attempts. If an attempt fails, it should wait for `delay` milliseconds before trying again. If all attempts fail, it rejects with the last encountered error.

Examples

Example 1:
let attempts = 0;
const flaky = async () => {
  attempts++;
  if (attempts < 3) throw new Error('Network error');
  return 'data';
};
await retry(flaky, 3, 50); // returns 'data'
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

3 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.