Created
October 23, 2022 07:04
-
-
Save styopdev/3f740b2e54e9b865e54c3b4b61ae348b to your computer and use it in GitHub Desktop.
Print numbers in range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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