mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Bump to v4.0.0.
This commit is contained in:
@@ -1,41 +1,52 @@
|
||||
import baseIndexOf from './baseIndexOf';
|
||||
import cacheIndexOf from './cacheIndexOf';
|
||||
import createCache from './createCache';
|
||||
import SetCache from './SetCache';
|
||||
import arrayIncludes from './arrayIncludes';
|
||||
import arrayIncludesWith from './arrayIncludesWith';
|
||||
import cacheHas from './cacheHas';
|
||||
import createSet from './createSet';
|
||||
import setToArray from './setToArray';
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
var LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.uniq` without support for callback shorthands
|
||||
* and `this` binding.
|
||||
* The base implementation of `_.uniqBy` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {Function} [iteratee] The function invoked per iteration.
|
||||
* @param {Function} [iteratee] The iteratee invoked per element.
|
||||
* @param {Function} [comparator] The comparator invoked per element.
|
||||
* @returns {Array} Returns the new duplicate free array.
|
||||
*/
|
||||
function baseUniq(array, iteratee) {
|
||||
function baseUniq(array, iteratee, comparator) {
|
||||
var index = -1,
|
||||
indexOf = baseIndexOf,
|
||||
includes = arrayIncludes,
|
||||
length = array.length,
|
||||
isCommon = true,
|
||||
isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
|
||||
seen = isLarge ? createCache() : null,
|
||||
result = [];
|
||||
result = [],
|
||||
seen = result;
|
||||
|
||||
if (seen) {
|
||||
indexOf = cacheIndexOf;
|
||||
if (comparator) {
|
||||
isCommon = false;
|
||||
} else {
|
||||
isLarge = false;
|
||||
includes = arrayIncludesWith;
|
||||
}
|
||||
else if (length >= LARGE_ARRAY_SIZE) {
|
||||
var set = iteratee ? null : createSet(array);
|
||||
if (set) {
|
||||
return setToArray(set);
|
||||
}
|
||||
isCommon = false;
|
||||
includes = cacheHas;
|
||||
seen = new SetCache;
|
||||
}
|
||||
else {
|
||||
seen = iteratee ? [] : result;
|
||||
}
|
||||
outer:
|
||||
while (++index < length) {
|
||||
var value = array[index],
|
||||
computed = iteratee ? iteratee(value, index, array) : value;
|
||||
computed = iteratee ? iteratee(value) : value;
|
||||
|
||||
if (isCommon && value === value) {
|
||||
if (isCommon && computed === computed) {
|
||||
var seenIndex = seen.length;
|
||||
while (seenIndex--) {
|
||||
if (seen[seenIndex] === computed) {
|
||||
@@ -47,8 +58,8 @@ function baseUniq(array, iteratee) {
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
else if (indexOf(seen, computed, 0) < 0) {
|
||||
if (iteratee || isLarge) {
|
||||
else if (!includes(seen, computed, comparator)) {
|
||||
if (seen !== result) {
|
||||
seen.push(computed);
|
||||
}
|
||||
result.push(value);
|
||||
|
||||
Reference in New Issue
Block a user