UNPKG

808 BJavaScriptView Raw
1import baseUniq from './_baseUniq';
2
3/**
4 * This method is like `_.uniq` except that it accepts `comparator` which
5 * is invoked to compare elements of `array`. The comparator is invoked with
6 * 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 */
22function uniqWith(array, comparator) {
23 return (array && array.length)
24 ? baseUniq(array, undefined, comparator)
25 : [];
26}
27
28export default uniqWith;