Presenting the "sleep sort", our favorite O(wtf) sorting algorithm. (C'mon, it's the weekend..) 😂

Apr 23, 2017 · 10:03 PM UTC

This is actually kinda genius. I'm giving respect for originality and comedic timing.
1
21
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
Push it to an array and you have a working algorithm :LOL:
1
4
With a little modification that could work really well as a quick way of scheduling the Web Audio API just ahead of time.
3
Someone is getting fired 😂
2
Works only for positive numbers :(
1
I tried in C#, works in .net framework but not in .net, they must have changed something about Parallel.ForEach.
2
Yes! It works! Ha-ha!
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
Check this out . function sorting(arr) { const sortArr = []; arr.forEach((a) => (sortArr[a] = a)); return sortArr.filter((s) => s != null); }
The complexity should be O(n) as sleeping does increase it. Pretty strong stuff!!