Created
July 25, 2022 06:21
-
-
Save laat/8e0666e2c38377de7ceb0890afc4560a 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
const sleep = (s) => | |
new Promise((resolve) => | |
setTimeout(() => resolve(s), s * 1000) | |
); | |
const sleepSort = async (arr) => { | |
const res = []; | |
await Promise.all( | |
arr | |
.map(sleep) | |
.map((x) => x.then(res.push.bind(res))) | |
); | |
return res; | |
}; | |
await sleepSort([1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment