Created
April 7, 2022 18:50
-
-
Save JoeCortopassi/ef5378b1db294283c8dff10ff924f08a 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