Created
November 6, 2020 10:59
-
-
Save joelxr/ed43a138ad296215980f4db787c7b88a to your computer and use it in GitHub Desktop.
quick sort
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 | |
const pivot = array[Math.floor(array.length / 2)] | |
return [ | |
...quickSort(array.filter(e => e < pivot)), | |
...array.filter(e => e === pivot), | |
...quickSort(array.filter(e => e > pivot)) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment