Created
September 26, 2022 17:08
-
-
Save joshkitt/de05998d3b3e61ac1e60a5b8ee34e5d3 to your computer and use it in GitHub Desktop.
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
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