Skip to content

Instantly share code, notes, and snippets.

@styopdev
Created October 23, 2022 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save styopdev/3f740b2e54e9b865e54c3b4b61ae348b to your computer and use it in GitHub Desktop.
Save styopdev/3f740b2e54e9b865e54c3b4b61ae348b to your computer and use it in GitHub Desktop.
Print numbers in range
function printNumbers(a, b, cb) {
if (a > b || typeof a !== 'number' || typeof b !== 'number') {
throw 'Incorrect arguments';
}
for(let i = a, counter = 0; i <= b; i++, counter++) {
setTimeout(() => {
cb(i);
}, 1000 * counter)
}
}
printNumbers(1, 5, (res) => console.log(res));
printNumbers(1, 5, (res) => alert(res));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment