Skip to content

Instantly share code, notes, and snippets.

@juliankrispel
Created October 28, 2013 07:05
Show Gist options
  • Save juliankrispel/7192470 to your computer and use it in GitHub Desktop.
Save juliankrispel/7192470 to your computer and use it in GitHub Desktop.
A quicksort implementation in CoffeeScript
arr = [900, 1, 39, 12, 8, 15, 39, 11, 100]
quicksort = (arr) ->
if(arr.length < 2)
return arr
unless arr or arr.length > 1
throw new Error 'Input invalid'
pivot = arr[0]
left = []
right = []
i = 0
for num in arr
left.push num if num < pivot
right.push num if num > pivot
_.union(quicksort(left), [pivot], quicksort right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment