In a recent xkcd's alt text, Randall Munroe suggested stacksort, a sort that searches StackOverflow for sorting functions and runs them until it returns the correct answer. So, I made it. If you like running arbitrary code in your browser, try it out.

Like (or hate) it? Comment on HackerNews
var output =
Output from the function.
Sorted using answer
How does it work?

As outlined by xkcd's recent alt text, this site downloads the top answers from StackOverflow for the tags "javascript" and "sort". It grabs the last code block in the answer (in theory, the "final" example), and tries to determine which function should be called. It proceeds to eval the code from StackOverflow, with the inputted data as the first parameter for the function.

If it returns a wrongly-sorted list (or you just want to keep playing), a link to "Try the next answer" will appear under the result.

You can view the code on GitHub. If you see any bugs (or just want to berate me), please file an issue.

Is it safe?

Uh… it evals both user input and random code, unchecked, from an external site. This is what security-minded folks would refer to as Very Bad™.

That being said, for what it is, it should be relatively harmless. The site will only fetch accepted answers, and it only uses answers that were posted before the xkcd was released (meaning that if someone posted malicious code now, it wouldn't matter). It also searches for potentially-malicious code (like the word "cookie"), and skips those. It's definitely not the safest thing, however at most it would probably just crash your browser.

Shamefully created by Gregory Koberger. Follow me on Twitter. I'm so sorry.
(Thanks to xkcd for the idea, and Eric Willis for helping out)