Skip to content

Instantly share code, notes, and snippets.

@HuangXiZhou
Last active April 19, 2018 00:04
Show Gist options
  • Save HuangXiZhou/8e04e903261e2882d96ff5d148887f30 to your computer and use it in GitHub Desktop.
Save HuangXiZhou/8e04e903261e2882d96ff5d148887f30 to your computer and use it in GitHub Desktop.
JavaScript QuickSort
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