No Description

sortedIndex.js 551B

123456789101112131415
  1. import cb from './_cb.js';
  2. import getLength from './_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. export default 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. }