Timeout Sort: The Accidental Sorting Algorithm

Timeout Sort: The Accidental Sorting Algorithm
javascript-memes, sorting-algorithm-memes, settimeout-memes, event-loop-memes, programming-humor-memes | ProgrammerHumor.io

Behold the accidental genius of setTimeout sorting! The code loops through an array and logs each value using setTimeout with the value itself as the delay. Since JavaScript's event loop processes timeouts in order of expiration, smaller numbers appear first in the console.

Congratulations! You've invented the world's most inefficient sorting algorithm with O(max(array)) time complexity. The array magically appears sorted in the console, not because of any actual sorting logic, but because the browser's event scheduler is doing all the work.

Somewhere, a computer science professor just felt a disturbance in the force.

More Like This