Skip to content

Instantly share code, notes, and snippets.

@devsnek
Created February 28, 2017 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devsnek/ab7f4919d3acee1231cfe770af568d0b to your computer and use it in GitHub Desktop.
Save devsnek/ab7f4919d3acee1231cfe770af568d0b to your computer and use it in GitHub Desktop.
slowest sort algorithm ever made
const unsorted = [2, 3, 4, 5, 1, 7, 10, 20];
function snekSort(arr) {
const out = [];
for (let i in arr) {
const current = arr[i];
const next = arr[parseInt(i) + 1];
if (i == arr.length - 1) out.splice(1, 0, arr[0]); // out.unshift(arr[0]);
else if (current < next) out.push(next);
else out.unshift(next);
}
return out;
}
console.log(snekSort(unsorted));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment