createSortedIndex.js 656 B

1234567891011121314151617181920
  1. var baseCallback = require('./baseCallback'),
  2. binaryIndex = require('./binaryIndex'),
  3. binaryIndexBy = require('./binaryIndexBy');
  4. /**
  5. * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
  6. *
  7. * @private
  8. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  9. * @returns {Function} Returns the new index function.
  10. */
  11. function createSortedIndex(retHighest) {
  12. return function(array, value, iteratee, thisArg) {
  13. return iteratee == null
  14. ? binaryIndex(array, value, retHighest)
  15. : binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1), retHighest);
  16. };
  17. }
  18. module.exports = createSortedIndex;