Created
February 28, 2017 04:37
-
-
Save devsnek/ab7f4919d3acee1231cfe770af568d0b to your computer and use it in GitHub Desktop.
slowest sort algorithm ever made
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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