Created
October 10, 2014 02:50
-
-
Save 0532/436b6c5cd2317a45ec3e to your computer and use it in GitHub Desktop.
Javascript recursive quicksort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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