13

Stacksort a la xkcd

 5 years ago
source link: https://www.tuicool.com/articles/hit/6nM7VzR
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK