Skip to content

Instantly share code, notes, and snippets.

@icambron
Last active August 29, 2015 14:03
Show Gist options
  • Save icambron/a2b4f8d5942b811f4c07 to your computer and use it in GitHub Desktop.
Save icambron/a2b4f8d5942b811f4c07 to your computer and use it in GitHub Desktop.
Slicker quicksort in coffee
#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