Skip to content

Instantly share code, notes, and snippets.

@arianf
Created February 9, 2015 16:13
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 arianf/926c79e57d1779408cc9 to your computer and use it in GitHub Desktop.
Save arianf/926c79e57d1779408cc9 to your computer and use it in GitHub Desktop.
_.sortedIndex = function(array, obj, iteratee, context) {
iteratee = cb(iteratee, context, 1);
var value = iteratee(obj) === undefined ? Infinity : iteratee(obj);
var low = 0, high = array.length;
while (low < high) {
var mid = Math.floor((low + high) / 2);
if (iteratee(array[mid]) <= value) 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