-
-
Save eengineergz/24bcbc5248a8c4e1671945e9512da57e 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(array) { | |
if (array.length <= 1) return array; | |
let pivot = array.shift(); | |
let left = array.filter((x) => x < pivot); | |
let right = array.filter((x) => x >= pivot); | |
let sortedLeft = quickSort(left); | |
let sortedRight = quickSort(right); | |
return [...sortedLeft, pivot, ...sortedRight]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment