Skip to content

Instantly share code, notes, and snippets.

@0532
Created October 10, 2014 02:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 0532/436b6c5cd2317a45ec3e to your computer and use it in GitHub Desktop.
Save 0532/436b6c5cd2317a45ec3e to your computer and use it in GitHub Desktop.
Javascript recursive quicksort
function quickSort(A) {
var smaller = []; var larger = [];
if (A.length <= 1)
return A;
for (var i = 1; i < A.length; i++) {
if (A[i] < A[0])
smaller.push(A[i]);
if (A[i] >= A[0])
larger.push(A[i]);
}
return quickSort(smaller).concat(A[0], quickSort(larger));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment