teapawt
$
JavaScript Daily
@JavaScriptDaily
23 Apr 2017
Presenting the "sleep sort", our favorite O(wtf) sorting algorithm. (C'mon, it's the weekend..) 😂
Apr 23, 2017 · 10:03 PM UTC
21
881
118
1,434
Relevant
Recent
Likes
Mark Kawakami
@skippykawakami
24 Apr 2017
This is actually kinda genius. I'm giving respect for originality and comedic timing.
1
21
Михаил Коптелов
@MikhailKoptelov
23 Apr 2017
Not deterministic. Anything <10ms can return in order of calling. Can fix it up with setTimeout(..., num * 1000); Time complx is the same!
1
18
Joanmi oficial
@joanmitter
23 Apr 2017
Push it to an array and you have a working algorithm :LOL:
1
4
stephband
@stephband
24 Apr 2017
With a little modification that could work really well as a quick way of scheduling the Web Audio API just ahead of time.
3
Joey Dias
@imjoeydias
24 Apr 2017
Someone is getting fired 😂
2
lpsoft
@lpsoft_pl
30 May 2017
Works only for positive numbers :(
1
Michael Gidron
@mbgidron
2 May 2017
Lol..
1
Dev Z.
@zyflovelam
24 Apr 2017
😄
Jon Donkin
@Jondonkin
4 Nov 2025
I tried in C#, works in .net framework but not in .net, they must have changed something about Parallel.ForEach.
2
Vladas Saulis
@thevs
29 Apr 2017
Yes! It works! Ha-ha!
Jordan Pittman
@jordanpittman
26 Apr 2017
let d=t=>new Promise(r=>setTimeout(()=>r(t),t));let s=c=>Promise.all(c.map(d));s([8,42,38,111,2,39,1]).then(console.log)
2
Cody Loyd
@codyloyd
23 Apr 2017
Nice one!
OhMyJersh
@OhMyJersh
23 Apr 2017
This is funny.
naresh vadlamani
@chenchu_naresh
20 Mar 2021
Check this out . function sorting(arr) { const sortArr = []; arr.forEach((a) => (sortArr[a] = a)); return sortArr.filter((s) => s != null); }
ohcibi
@ohcibi
27 Apr 2017
The complexity should be O(n) as sleeping does increase it. Pretty strong stuff!!
Adrián Hernández
@ahbarrios
24 Apr 2017
wtf!
Khalid Nowaf | خالد نواف
@Khalid_nowaf
24 Apr 2017
welcome to JS world 😅