Skip to content

Instantly share code, notes, and snippets.

@MiradorOne
Created August 1, 2023 21:18
Show Gist options
  • Save MiradorOne/a09b4fe905659775936b625fb487724c to your computer and use it in GitHub Desktop.
Save MiradorOne/a09b4fe905659775936b625fb487724c to your computer and use it in GitHub Desktop.
Quick Sort algorithm
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