Technically Horrifyingly Correct

Technically Horrifyingly Correct
javascript-memes, algorithms-memes, sorting-memes, big-o-notation-memes, settimeout-memes | ProgrammerHumor.io

The code creates a sorting algorithm that's technically O(n) but for all the wrong reasons. Instead of actually sorting the array, it's using setTimeout() with the array value as the delay time in milliseconds. The smallest numbers appear first in the console simply because their timeouts complete faster!

It's like telling your friends you've invented a revolutionary sorting algorithm, but you're actually just making each number raise its hand after waiting for X milliseconds where X equals its own value. Pure chaotic genius.

The browser's event loop is doing the sorting for free! Computational complexity professors are currently rolling in their graves (even the ones who aren't dead yet).

More Like This