Last active
July 15, 2021 02:47
-
-
Save JayMGurav/60a4329d5989085ce3e74b46c7ac4405 to your computer and use it in GitHub Desktop.
serialize random timers to print numbers from 0-10 in order
This file contains 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 randomTime() { | |
const min = 0, max = 6; | |
return (Math.floor(Math.random() * (max - min + 1)) + min) * 1000;; | |
} | |
Array.from({length:10}, (_, k) => k+1).reduce(async (prev, curr) => { | |
await prev; | |
return new Promise((resolve) => { | |
setTimeout(resolve,randomTime(), console.log(curr)) | |
}); | |
}, Promise.resolve(console.log(0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment