// Contract:
//
// Create a function with a signature:
//
// retry(fn, retryDelay, maxAttempts) -> promise
//
// Implementation:
//
// • retry should call fn; if fn() throws an error error, wait for the retry delay to retry calling fn.
// • if fn() succeeds, the returned promise should resolve with the result of fn()
// • in fn() has been attempted maxAttempts with an error each time, returned promise should reject with the last error
//
function retry(fn, retryDelay, maxAttempts) {
/* ... */
}
I provided some basic assertions to valid the code was working. Solution is about 12-13 lines of code.I remember being able to solve this sight unseen within 15 minutes; I was asked this question on an on-site by a large, well-known tech company. When I tried it again pre-interview it took longer (~30 minutes). Thoughts?