Skip to content

Instantly share code, notes, and snippets.

@joshkitt
Created September 26, 2022 17:08
Show Gist options
  • Save joshkitt/de05998d3b3e61ac1e60a5b8ee34e5d3 to your computer and use it in GitHub Desktop.
Save joshkitt/de05998d3b3e61ac1e60a5b8ee34e5d3 to your computer and use it in GitHub Desktop.
const quicksort = (a) => {
if (a.length <= 1) {
return a
}
const pivot = a[0]
const low = []
const hi = []
a.map(i => {
i < pivot ? low.push(i) : null
i > pivot ? hi.push(i) : null
})
return [...quicksort(low), pivot, ...quicksort(hi)]
}
export { quicksort }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment