Skip to content

Instantly share code, notes, and snippets.

@chadhietala
Last active September 25, 2015 21:58
Show Gist options
  • Save chadhietala/991339 to your computer and use it in GitHub Desktop.
Save chadhietala/991339 to your computer and use it in GitHub Desktop.
Quicksort in Javascript
var a = [34,2,121,4,66];
function quickSort(arr){
if (arr.length == 0)
return [];
var left = [],
right = [],
pivot = arr[0];
for (var i = 1; i < arr.length; i++) {
if (arr[i] < pivot) {
left.push(arr[i]);
} else {
right.push(arr[i]);
}
}
return quickSort(left).concat(pivot, quickSort(right));
}
console.log(quickSort(a));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment