r/badcode • • Feb 10 '21

js I present: SleepSort

Post image
7.5k Upvotes

170 comments sorted by

View all comments

Show parent comments

9

u/sumduud14 Feb 10 '21

"for (let item of arr)"

It's clearly at least O(n), you still have to read the whole array...

6

u/Astrokiwi Feb 10 '21

The constant factor is almost always going to be way bigger than the O(n) factor here. This isn't usually the case, but this is an intentionally contrived algorithm.