sortedUniqBy.js 698B

123456789101112131415161718192021222324252627
  1. var baseIteratee = require('./_baseIteratee'),
  2. baseSortedUniq = require('./_baseSortedUniq');
  3. /**
  4. * This method is like `_.uniqBy` except that it's designed and optimized
  5. * for sorted arrays.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 4.0.0
  10. * @category Array
  11. * @param {Array} array The array to inspect.
  12. * @param {Function} [iteratee] The iteratee invoked per element.
  13. * @returns {Array} Returns the new duplicate free array.
  14. * @example
  15. *
  16. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  17. * // => [1.1, 2.3]
  18. */
  19. function sortedUniqBy(array, iteratee) {
  20. return (array && array.length)
  21. ? baseSortedUniq(array, baseIteratee(iteratee, 2))
  22. : [];
  23. }
  24. module.exports = sortedUniqBy;