Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. var quickSort = function(arr) {
  2.   if (arr.length <= 1) { return arr; }
  3.   var pivotIndex = Math.floor(arr.length / 2);
  4.   var pivot = arr.splice(pivotIndex, 1)[0];
  5.   var left = [];
  6.   var right = [];
  7.   for (var i = 0; i < arr.length; i++){
  8.     if (arr[i] < pivot) {
  9.       left.push(arr[i]);
  10.     } else {
  11.       right.push(arr[i]);
  12.     }
  13.   }
  14.   return quickSort(left).concat([pivot], quickSort(right));
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement