Created
December 1, 2021 01:17
-
-
Save JoeCortopassi/6cc3520d2bd0ca558107f5082940a411 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(arr) { | |
if (arr.length <= 1) return arr; | |
const pivot = arr[Math.floor(arr.length/2)]; | |
const lower = arr.filter(val => val < pivot); | |
const equal = arr.filter(val => val === pivot); | |
const higher = arr.filter(val => val > pivot); | |
return [...quickSort(lower), ...quickSort(equal), ...quickSort(higher)]; | |
} | |
const test = [6,2,5,3,4,1,9,7,0,8]; | |
console.log(quickSort(test)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment