Created
October 28, 2013 07:05
-
-
Save juliankrispel/7192470 to your computer and use it in GitHub Desktop.
A quicksort implementation in CoffeeScript
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
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