Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function quickSort(arr) {
if (arr.length <= 1) {
return arr;
}
const less = [];
const greater = [];
const pivot = arr[arr.length - 1];
for (let i = 0; i < arr.length - 1; ++i) {
const num = arr[i];
if (num < pivot) {
less.push(num);
} else {
greater.push(num);
}
}
return [...quickSort(less), pivot, ...quickSort(greater)];
}
const arr = [9, 4, 1, 6, 7, 3, 8, 2, 5];
quickSort(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.