Last active
June 6, 2022 17:36
-
-
Save bradoyler/608cc5120662a1f5820b0ba0516c20d5 to your computer and use it in GitHub Desktop.
sorting algorithm using setTimeout
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 sleepSort(arr) { | |
arr.forEach((n) => setTimeout(() => console.log(n), n)) | |
} | |
const arr = [9, 5, 3, 99, 11, 2, 0] | |
sleepSort(arr) | |
/* stdout: | |
0 | |
2 | |
3 | |
5 | |
9 | |
11 | |
99 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related reading: