Skip to content

Instantly share code, notes, and snippets.

@eengineergz
Created February 27, 2021 05:16
Show Gist options
  • Save eengineergz/24bcbc5248a8c4e1671945e9512da57e to your computer and use it in GitHub Desktop.
Save eengineergz/24bcbc5248a8c4e1671945e9512da57e to your computer and use it in GitHub Desktop.
function quickSort(array) {
if (array.length <= 1) return array;
let pivot = array.shift();
let left = array.filter((x) => x < pivot);
let right = array.filter((x) => x >= pivot);
let sortedLeft = quickSort(left);
let sortedRight = quickSort(right);
return [...sortedLeft, pivot, ...sortedRight];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment