Last active
April 1, 2019 01:24
-
-
Save quisido/2ab9c2467b4c70e1652e4c4a74111787 to your computer and use it in GitHub Desktop.
Implementing Quicksort in JavaScript
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 = ( | |
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