Created
July 13, 2020 15:20
-
-
Save BetterProgramming/e5ba19f3506b77befed000412a162103 to your computer and use it in GitHub Desktop.
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
function quickSort(originalArray) { | |
if (originalArray.length <= 1) { | |
return originalArray; | |
} | |
else | |
{ | |
let leftSide = []; | |
let rightSide = []; | |
let newArray = []; | |
let pivot = originalArray.pop(); | |
let length = originalArray.length; | |
for (let i = 0; i < length; i++) { | |
if (originalArray[i] <= pivot) { | |
leftSide.push(originalArray[i]); | |
} | |
else | |
{ | |
rightSide.push(originalArray[i]); | |
} | |
}//END FOR | |
return newArray.concat(quickSort(leftSide), pivot, quickSort(rightSide)); | |
} //END ELSE | |
}//END QUICKSORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment