No Description

sortedIndex.js 577B

1234567891011121314151617
  1. var _cb = require('./_cb.js');
  2. var _getLength = require('./_getLength.js');
  3. // Use a comparator function to figure out the smallest index at which
  4. // an object should be inserted so as to maintain order. Uses binary search.
  5. function sortedIndex(array, obj, iteratee, context) {
  6. iteratee = _cb(iteratee, context, 1);
  7. var value = iteratee(obj);
  8. var low = 0, high = _getLength(array);
  9. while (low < high) {
  10. var mid = Math.floor((low + high) / 2);
  11. if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
  12. }
  13. return low;
  14. }
  15. module.exports = sortedIndex;