Created
March 2, 2020 07:16
-
-
Save gngenius02/2d2ff248da94c21a296e82d952364140 to your computer and use it in GitHub Desktop.
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
//delay fn | |
const delay = (time) => new Promise((resolve) => setTimeout(resolve, parseInt(time * 1000))); | |
//random fn | |
const random = () => Math.random() * 1.5; | |
const iterationArray = new Array(10); | |
const runFn = async (rounds) => { | |
let i = -1 | |
for await (round of rounds) { | |
const time = random() | |
await delay(time); | |
rounds[++i] = parseFloat(time) | |
console.log(`${i} rounds completed.`) | |
} | |
return rounds; | |
} | |
runFn(iterationArray).then((respFromRun) => { | |
const reduced = respFromRun.reduce((p, c) => p + c, 0); | |
console.log({ respFromRun, reduced }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment