Skip to content

Instantly share code, notes, and snippets.

@jergason
Created November 23, 2014 15:37
Show Gist options
  • Save jergason/971f298621ae7d9511ed to your computer and use it in GitHub Desktop.
Save jergason/971f298621ae7d9511ed to your computer and use it in GitHub Desktop.
quicksort in js
function quicksort(list) {
if (list.length == 0) {
return list;
}
var pivot = list.splice(Math.floor(list.length / 2), 1)[0];
var smaller = quicksort(list.filter(function(i) {
return i <= pivot;
}));
var larger = quicksort(list.filter(function(i) {
return i > pivot;
}));
return smaller.concat(pivot, larger);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment