MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / baseUniq

Function baseUniq

MathBox/mathbox-bundle.js:36437–36472  ·  view source on GitHub ↗

* The base implementation of `_.uniq` without support for callback shorthands * or `thisArg` binding. * * @private * @param {Array} array The array to process. * @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted. * @param {Function} [callback]

(array, isSorted, callback)

Source from the content-addressed store, hash-verified

36435 * @returns {Array} Returns a duplicate-value-free array.
36436 */
36437 function baseUniq(array, isSorted, callback) {
36438 var index = -1,
36439 indexOf = getIndexOf(),
36440 length = array ? array.length : 0,
36441 result = [];
36442
36443 var isLarge = !isSorted && length >= largeArraySize && indexOf === baseIndexOf,
36444 seen = (callback || isLarge) ? getArray() : result;
36445
36446 if (isLarge) {
36447 var cache = createCache(seen);
36448 indexOf = cacheIndexOf;
36449 seen = cache;
36450 }
36451 while (++index < length) {
36452 var value = array[index],
36453 computed = callback ? callback(value, index, array) : value;
36454
36455 if (isSorted
36456 ? !index || seen[seen.length - 1] !== computed
36457 : indexOf(seen, computed) < 0
36458 ) {
36459 if (callback || isLarge) {
36460 seen.push(computed);
36461 }
36462 result.push(value);
36463 }
36464 }
36465 if (isLarge) {
36466 releaseArray(seen.array);
36467 releaseObject(seen);
36468 } else if (callback) {
36469 releaseArray(seen);
36470 }
36471 return result;
36472 }
36473
36474 /**
36475 * Creates a function that aggregates a collection, creating an object composed

Callers 3

unionFunction · 0.85
uniqFunction · 0.85
xorFunction · 0.85

Calls 7

getIndexOfFunction · 0.85
getArrayFunction · 0.85
releaseArrayFunction · 0.85
releaseObjectFunction · 0.85
createCacheFunction · 0.70
callbackFunction · 0.70
indexOfFunction · 0.70

Tested by

no test coverage detected