Skip to content

Instantly share code, notes, and snippets.

@megawac
Created August 5, 2014 04:02
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 megawac/f4849d5ecc85539264ea to your computer and use it in GitHub Desktop.
Save megawac/f4849d5ecc85539264ea to your computer and use it in GitHub Desktop.
function sortedIndex(array, value, iterator, pivot) {
var low = 0,
high = array.length,
target = iterator(value);
while (low - pivot < high) {
var mid = (((low + high) >>> 1) + pivot) % array.length;
if (iterator(array[mid]) < target) low = mid + 1;
else high = mid;
}
return low;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment