Skip to content

Instantly share code, notes, and snippets.

@island205
Created October 25, 2012 09:04
Show Gist options
  • Select an option

  • Save island205/3951536 to your computer and use it in GitHub Desktop.

Select an option

Save island205/3951536 to your computer and use it in GitHub Desktop.
quickSort = (arr)->
debugger
return arr if arr.length < 2
left = []
right = []
for i in [1...arr.length]
if arr[0] > arr[i]
left.push arr[i]
else
right.push arr[i]
debugger
[].concat quickSort(left), arr[0], quickSort(right)
#test
console.log quickSort [1,2,3,3,4,6, 9, 2, 1]
console.log quickSort [1]
console.log quickSort [0]
console.log quickSort [1,0]
console.log quickSort [1,0,1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment