Skip to content

Instantly share code, notes, and snippets.

@joelxr
Created November 6, 2020 10:59
Show Gist options
  • Save joelxr/ed43a138ad296215980f4db787c7b88a to your computer and use it in GitHub Desktop.
Save joelxr/ed43a138ad296215980f4db787c7b88a to your computer and use it in GitHub Desktop.
quick sort
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