No Description

sortedIndex.js 585B

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