Created
August 1, 2023 21:18
-
-
Save MiradorOne/a09b4fe905659775936b625fb487724c to your computer and use it in GitHub Desktop.
Quick Sort algorithm
This file contains hidden or 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 = (array) => { | |
if (array.length < 2) { | |
return array | |
} | |
const pivot = array[0] | |
const arrayWithoutPivot = array.slice(1) | |
const less = arrayWithoutPivot.filter((n) => n < pivot) | |
const greater = arrayWithoutPivot.filter((n) => n > pivot) | |
return [...quickSort(less), pivot, ...quickSort(greater)] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment