Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Last active June 6, 2022 17:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradoyler/608cc5120662a1f5820b0ba0516c20d5 to your computer and use it in GitHub Desktop.
Save bradoyler/608cc5120662a1f5820b0ba0516c20d5 to your computer and use it in GitHub Desktop.
sorting algorithm using setTimeout
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
*/