選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

uniqWith.js 958B

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 order of result values is
  5. * determined by the order they occur in the array.The comparator is invoked
  6. * with two arguments: (arrVal, othVal).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Array
  12. * @param {Array} array The array to inspect.
  13. * @param {Function} [comparator] The comparator invoked per element.
  14. * @returns {Array} Returns the new duplicate free array.
  15. * @example
  16. *
  17. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  18. *
  19. * _.uniqWith(objects, _.isEqual);
  20. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  21. */
  22. function uniqWith(array, comparator) {
  23. comparator = typeof comparator == 'function' ? comparator : undefined;
  24. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  25. }
  26. module.exports = uniqWith;