Skip to content

Instantly share code, notes, and snippets.

@squalvj
Created April 29, 2020 09:22
Show Gist options
  • Save squalvj/85a2bcee8a737781eeac470aabf83b42 to your computer and use it in GitHub Desktop.
Save squalvj/85a2bcee8a737781eeac470aabf83b42 to your computer and use it in GitHub Desktop.
Super quicksort algorithm
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