uniqWith.js 812 B

12345678910111213141516171819202122232425262728
  1. var baseUniq = require('./_baseUniq');
  2. /**
  3. * This method is like `_.uniq` except that it accepts `comparator` which
  4. * is invoked to compare elements of `array`. The comparator is invoked with
  5. * two arguments: (arrVal, othVal).
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 4.0.0
  10. * @category Array
  11. * @param {Array} array The array to inspect.
  12. * @param {Function} [comparator] The comparator invoked per element.
  13. * @returns {Array} Returns the new duplicate free array.
  14. * @example
  15. *
  16. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  17. *
  18. * _.uniqWith(objects, _.isEqual);
  19. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  20. */
  21. function uniqWith(array, comparator) {
  22. return (array && array.length)
  23. ? baseUniq(array, undefined, comparator)
  24. : [];
  25. }
  26. module.exports = uniqWith;