sortedIndexBy.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. var baseIteratee = require('./_baseIteratee'),
  2. baseSortedIndexBy = require('./_baseSortedIndexBy');
  3. /**
  4. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  5. * which is invoked for `value` and each element of `array` to compute their
  6. * sort ranking. The iteratee is invoked with one argument: (value).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Array
  12. * @param {Array} array The sorted array to inspect.
  13. * @param {*} value The value to evaluate.
  14. * @param {Array|Function|Object|string} [iteratee=_.identity]
  15. * The iteratee invoked per element.
  16. * @returns {number} Returns the index at which `value` should be inserted
  17. * into `array`.
  18. * @example
  19. *
  20. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  21. *
  22. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  23. * // => 0
  24. *
  25. * // The `_.property` iteratee shorthand.
  26. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  27. * // => 0
  28. */
  29. function sortedIndexBy(array, value, iteratee) {
  30. return baseSortedIndexBy(array, value, baseIteratee(iteratee));
  31. }
  32. module.exports = sortedIndexBy;