Last active
August 29, 2015 14:03
-
-
Save icambron/a2b4f8d5942b811f4c07 to your computer and use it in GitHub Desktop.
Slicker quicksort in coffee
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
#adapted from The Joy of Clojure, second edition, page 132-135 | |
quicksort = (array) -> | |
split = (work) -> | |
[part, parts...] = work | |
if part? | |
if part.length | |
[pivot, xs...] = part | |
split([ | |
(x for x in xs when x < pivot), | |
pivot, | |
(x for x in xs when x >= pivot) | |
].concat(parts)) | |
else | |
[].concat(part, split(parts)) | |
else | |
[] | |
split [array] | |
console.log quicksort([200, 27, 12, 1, 1, 4, 57, 3, 2, 220, 220]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment