Created
April 29, 2020 09:22
-
-
Save squalvj/85a2bcee8a737781eeac470aabf83b42 to your computer and use it in GitHub Desktop.
Super quicksort algorithm
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 quickSort = list => { | |
if (list.length < 2) | |
return list; | |
let pivot = list[0]; | |
let left = []; | |
let right = []; | |
for (let i = 1, total = list.length; i < total; i++){ | |
if (list[i] < pivot) | |
left.push(list[i]); | |
else | |
right.push(list[i]); | |
} | |
return [ | |
...quickSort(left), | |
pivot, | |
...quickSort(right) | |
]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment