I'm studying some common algorithms implementations in JavaScript, and found this one while looking for quicksort: https://rawgit.com/escherba/algorithms-in-javascript/master/src/quickmiddle-sort.js
It implements an array partition function as well:
function partition(array, left, right) {
var pivot = array[(left + right) >>> 1];
while (left <= right) {
while (array[left] < pivot) { left++; }
while (array[right] > pivot) { right--; }
if (left <= right) {
var temp = array[left];
array[left++] = array[right];
array[right--] = temp;
}
}
return left;
}
I wonder what is the math behind the bitwise operation, I'm quite a newbie with them.