Skip to content

Instantly share code, notes, and snippets.

@quisido
Last active April 1, 2019 01:24
Show Gist options
  • Save quisido/2ab9c2467b4c70e1652e4c4a74111787 to your computer and use it in GitHub Desktop.
Save quisido/2ab9c2467b4c70e1652e4c4a74111787 to your computer and use it in GitHub Desktop.
Implementing Quicksort in JavaScript
const quickSort = (
unsortedArray,
comparator = defaultComparator
) => {
// Create a sortable array to return.
const sortedArray = [...unsortedArray];
// Recursively sort sub-arrays.
const recursiveSort = (start, end) => {
// If this sub-array is empty, it's sorted.
if (end - start < 1) {
return;
}
const pivotValue = sortedArray[end];
let splitIndex = start;
};
// Sort the entire array.
recursiveSort(0, unsortedArray.length - 1);
return sortedArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment