Skip to content

Instantly share code, notes, and snippets.

@vidul-nikolaev-petrov
Last active August 29, 2015 14:18
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 vidul-nikolaev-petrov/366313099f99e5fc6208 to your computer and use it in GitHub Desktop.
Save vidul-nikolaev-petrov/366313099f99e5fc6208 to your computer and use it in GitHub Desktop.
Quick sort
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