Skip to content

Instantly share code, notes, and snippets.

@missett
Created October 24, 2013 11:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save missett/7135816 to your computer and use it in GitHub Desktop.
Save missett/7135816 to your computer and use it in GitHub Desktop.
Recursive Quicksort implementation in JS
function quicksort(input) {
if(input.length === 0) return input;
var head = input[0],
tail = input.slice(1);
var less = tail.filter(function(i) {
return i < head ? true : false;
});
var greaterOrEqual = tail.filter(function(i) {
return i >= head ? true : false;
});
return quicksort(less).concat([head], quicksort(greaterOrEqual));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment