Last active
April 19, 2018 00:04
-
-
Save HuangXiZhou/8e04e903261e2882d96ff5d148887f30 to your computer and use it in GitHub Desktop.
JavaScript QuickSort
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 < 2) return arr; | |
const pivot = arr[~~(0 + Math.random() * arr.length)]; | |
return [ | |
...quickSort(arr.filter(v => v < pivot)), | |
...arr.filter(v => v === pivot), | |
...quickSort(arr.filter(v => v > pivot)), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment