source: imaps-frontend/node_modules/lodash-es/_baseUniq.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import SetCache from './_SetCache.js';
2import arrayIncludes from './_arrayIncludes.js';
3import arrayIncludesWith from './_arrayIncludesWith.js';
4import cacheHas from './_cacheHas.js';
5import createSet from './_createSet.js';
6import setToArray from './_setToArray.js';
7
8/** Used as the size to enable large array optimizations. */
9var LARGE_ARRAY_SIZE = 200;
10
11/**
12 * The base implementation of `_.uniqBy` without support for iteratee shorthands.
13 *
14 * @private
15 * @param {Array} array The array to inspect.
16 * @param {Function} [iteratee] The iteratee invoked per element.
17 * @param {Function} [comparator] The comparator invoked per element.
18 * @returns {Array} Returns the new duplicate free array.
19 */
20function baseUniq(array, iteratee, comparator) {
21 var index = -1,
22 includes = arrayIncludes,
23 length = array.length,
24 isCommon = true,
25 result = [],
26 seen = result;
27
28 if (comparator) {
29 isCommon = false;
30 includes = arrayIncludesWith;
31 }
32 else if (length >= LARGE_ARRAY_SIZE) {
33 var set = iteratee ? null : createSet(array);
34 if (set) {
35 return setToArray(set);
36 }
37 isCommon = false;
38 includes = cacheHas;
39 seen = new SetCache;
40 }
41 else {
42 seen = iteratee ? [] : result;
43 }
44 outer:
45 while (++index < length) {
46 var value = array[index],
47 computed = iteratee ? iteratee(value) : value;
48
49 value = (comparator || value !== 0) ? value : 0;
50 if (isCommon && computed === computed) {
51 var seenIndex = seen.length;
52 while (seenIndex--) {
53 if (seen[seenIndex] === computed) {
54 continue outer;
55 }
56 }
57 if (iteratee) {
58 seen.push(computed);
59 }
60 result.push(value);
61 }
62 else if (!includes(seen, computed, comparator)) {
63 if (seen !== result) {
64 seen.push(computed);
65 }
66 result.push(value);
67 }
68 }
69 return result;
70}
71
72export default baseUniq;
Note: See TracBrowser for help on using the repository browser.