react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / array / uniq.js
80742 viewsvar baseCallback = require('../internal/baseCallback'),1baseUniq = require('../internal/baseUniq'),2isIterateeCall = require('../internal/isIterateeCall'),3sortedUniq = require('../internal/sortedUniq');45/**6* Creates a duplicate-free version of an array, using7* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)8* for equality comparisons, in which only the first occurence of each element9* is kept. Providing `true` for `isSorted` performs a faster search algorithm10* for sorted arrays. If an iteratee function is provided it is invoked for11* each element in the array to generate the criterion by which uniqueness12* is computed. The `iteratee` is bound to `thisArg` and invoked with three13* arguments: (value, index, array).14*15* If a property name is provided for `iteratee` the created `_.property`16* style callback returns the property value of the given element.17*18* If a value is also provided for `thisArg` the created `_.matchesProperty`19* style callback returns `true` for elements that have a matching property20* value, else `false`.21*22* If an object is provided for `iteratee` the created `_.matches` style23* callback returns `true` for elements that have the properties of the given24* object, else `false`.25*26* @static27* @memberOf _28* @alias unique29* @category Array30* @param {Array} array The array to inspect.31* @param {boolean} [isSorted] Specify the array is sorted.32* @param {Function|Object|string} [iteratee] The function invoked per iteration.33* @param {*} [thisArg] The `this` binding of `iteratee`.34* @returns {Array} Returns the new duplicate-value-free array.35* @example36*37* _.uniq([2, 1, 2]);38* // => [2, 1]39*40* // using `isSorted`41* _.uniq([1, 1, 2], true);42* // => [1, 2]43*44* // using an iteratee function45* _.uniq([1, 2.5, 1.5, 2], function(n) {46* return this.floor(n);47* }, Math);48* // => [1, 2.5]49*50* // using the `_.property` callback shorthand51* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');52* // => [{ 'x': 1 }, { 'x': 2 }]53*/54function uniq(array, isSorted, iteratee, thisArg) {55var length = array ? array.length : 0;56if (!length) {57return [];58}59if (isSorted != null && typeof isSorted != 'boolean') {60thisArg = iteratee;61iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;62isSorted = false;63}64iteratee = iteratee == null ? iteratee : baseCallback(iteratee, thisArg, 3);65return (isSorted)66? sortedUniq(array, iteratee)67: baseUniq(array, iteratee);68}6970module.exports = uniq;717273