Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
958 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var baseUniq = require('./_baseUniq');
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * This method is like `_.uniq` except that it accepts `comparator` which
|
---|
| 5 | * is invoked to compare elements of `array`. The order of result values is
|
---|
| 6 | * determined by the order they occur in the array.The comparator is invoked
|
---|
| 7 | * with two arguments: (arrVal, othVal).
|
---|
| 8 | *
|
---|
| 9 | * @static
|
---|
| 10 | * @memberOf _
|
---|
| 11 | * @since 4.0.0
|
---|
| 12 | * @category Array
|
---|
| 13 | * @param {Array} array The array to inspect.
|
---|
| 14 | * @param {Function} [comparator] The comparator invoked per element.
|
---|
| 15 | * @returns {Array} Returns the new duplicate free array.
|
---|
| 16 | * @example
|
---|
| 17 | *
|
---|
| 18 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
---|
| 19 | *
|
---|
| 20 | * _.uniqWith(objects, _.isEqual);
|
---|
| 21 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
|
---|
| 22 | */
|
---|
| 23 | function uniqWith(array, comparator) {
|
---|
| 24 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
---|
| 25 | return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | module.exports = uniqWith;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.