Last active
August 29, 2015 14:18
-
-
Save vidul-nikolaev-petrov/366313099f99e5fc6208 to your computer and use it in GitHub Desktop.
Quick sort
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(list) { | |
if (!list.length) return []; | |
var left = [], | |
right = [], | |
center = list[0]; | |
for (var i = 1; i < list.length; i++) { | |
if (list[i] < center) { | |
left.push(list[i]); | |
} | |
else { | |
right.push(list[i]); | |
} | |
}; | |
return quickSort(left) + center + ',' + quickSort(right); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment