StackSort Sort
A few days ago, a comic strip about inefficient sorting methods was published on xkcd.com . The alt-text to it talked about sorting using the StackSort method, which consists in downloading blocks of code from StackOverflow that can be found by the query “sort the list” and run one by one until a workable option is found. Rave? Still not nonsense! Meet the StackSort JavaScript implementation at Github .
The script downloads the highest rated answers from StackOverflow to the questions marked with the sort and javascript tags and tries to execute the last block of code in the answer, assuming that this is the final version of the algorithm. Yes, that's right, it takes a piece of code from the Internet and does eval (), so be careful! However, the author tried to do everything possible so that the algorithm was safe - he takes the code only from answers that are marked as accepted, and only from those that were published before the appearance of the XKCD comic strip, so that someone does not specifically attach malicious code.
If the code block is executed without errors and returns an array, the result is shown to the user. If it is wrong, you can try further. The algorithm works with both numbers and strings and JSON objects. As for efficiency - in the Chromium browser under Ubuntu, the list of several numbers is sorted for 5-10 seconds (in Firefox, StackSort did not work for me). Slowly, but very extensively and universally, using the collective mind of the entire Internet.
UPD: Thanks to Athari for the list of working solutions compiled using StackSort:
The script downloads the highest rated answers from StackOverflow to the questions marked with the sort and javascript tags and tries to execute the last block of code in the answer, assuming that this is the final version of the algorithm. Yes, that's right, it takes a piece of code from the Internet and does eval (), so be careful! However, the author tried to do everything possible so that the algorithm was safe - he takes the code only from answers that are marked as accepted, and only from those that were published before the appearance of the XKCD comic strip, so that someone does not specifically attach malicious code.
If the code block is executed without errors and returns an array, the result is shown to the user. If it is wrong, you can try further. The algorithm works with both numbers and strings and JSON objects. As for efficiency - in the Chromium browser under Ubuntu, the list of several numbers is sorted for 5-10 seconds (in Firefox, StackSort did not work for me). Slowly, but very extensively and universally, using the collective mind of the entire Internet.
UPD: Thanks to Athari for the list of working solutions compiled using StackSort:
Answers work:
stackoverflow.com/questions/12137690/javascript-sort-sparse-array-keep-indexes#12137767
stackoverflow.com/questions/14761032/infinite-recursion-in-javascript-quicksort#14761203
stackoverflow.com/questions/8175093 / simple-function-to-sort-a-json-object-using-javascript # 8175221
stackoverflow.com/questions/9280360/javascript-function-returning-unique-values-sorted-by-count#9280565 Answers
partially work:
stackoverflow .com / questions / 1359761 / sorting-a-javascript-object # 1359808 Answers
do not work (among those that started and returned an array):
stackoverflow.com/questions/4833651/javascript-array-sort-and-unique#4833835
stackoverflow.com/ questions / 5326880 / sort-array-keys-by-value # 5327363
It took 6 pages, then issued: "Out of answers from StackOverflow!"
To all the answers there are strongly overstated comments about StackSort. :)