Skip to content

Commit

Permalink
complete hourglassSum
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarlsson committed Mar 14, 2019
1 parent d9642c9 commit bdd81d1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Write a function that to retries a request after a delay

const setTimeoutPromise = async (delayMS) => {
return new Promise(resolve => {
setTimeout(resolve, delayMS);
});
}

const retry = (cb, delayMS, maxAttempts, attempts = 0) => {

return new Promise((resolve, reject) => {
if (attempts >= maxAttempts) {
reject('Max Attempts Failure');
} else {
try {
resolve(cb());
} catch (err) {
setTimeoutPromise(delayMS)
.then(() => {
retry(cb, delayMS, maxAttempts, ++attempts)
.catch(() => { reject('Max Attempts Failure') });
})
.catch(() => { reject('Max Attempts Failure') });
}
}
});
}

const callback = () => {
throw new Error('whoops!');
return 'Hello';
}

retry(callback, 500, 3)
.then(console.log)
.catch(err => console.log('final error', err));
8 changes: 8 additions & 0 deletions src/rotArrLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@
function rotLeft(arr, d) {

}

const test1 = [1,2,3,4,5];

console.log('rotLeft(test1, 2)', rotLeft(test1, 2)); // [3,4,5,1,2]
// console.log('rotLeft(test1, 5)', rotLeft(test1, 5)); // [1,2,3,4,5]


//abbrevaite word accesibility => a11y

0 comments on commit bdd81d1

Please sign in to comment.