Skip to content

Instantly share code, notes, and snippets.

@yangjunjun
Forked from missett/JS Quicksort
Created October 24, 2013 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangjunjun/7135883 to your computer and use it in GitHub Desktop.
Save yangjunjun/7135883 to your computer and use it in GitHub Desktop.
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