source: trip-planner-front/node_modules/lodash/_baseDifference.js@ 6fe77af

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: 1.9 KB
Line 
1var SetCache = require('./_SetCache'),
2 arrayIncludes = require('./_arrayIncludes'),
3 arrayIncludesWith = require('./_arrayIncludesWith'),
4 arrayMap = require('./_arrayMap'),
5 baseUnary = require('./_baseUnary'),
6 cacheHas = require('./_cacheHas');
7
8/** Used as the size to enable large array optimizations. */
9var LARGE_ARRAY_SIZE = 200;
10
11/**
12 * The base implementation of methods like `_.difference` without support
13 * for excluding multiple arrays or iteratee shorthands.
14 *
15 * @private
16 * @param {Array} array The array to inspect.
17 * @param {Array} values The values to exclude.
18 * @param {Function} [iteratee] The iteratee invoked per element.
19 * @param {Function} [comparator] The comparator invoked per element.
20 * @returns {Array} Returns the new array of filtered values.
21 */
22function baseDifference(array, values, iteratee, comparator) {
23 var index = -1,
24 includes = arrayIncludes,
25 isCommon = true,
26 length = array.length,
27 result = [],
28 valuesLength = values.length;
29
30 if (!length) {
31 return result;
32 }
33 if (iteratee) {
34 values = arrayMap(values, baseUnary(iteratee));
35 }
36 if (comparator) {
37 includes = arrayIncludesWith;
38 isCommon = false;
39 }
40 else if (values.length >= LARGE_ARRAY_SIZE) {
41 includes = cacheHas;
42 isCommon = false;
43 values = new SetCache(values);
44 }
45 outer:
46 while (++index < length) {
47 var value = array[index],
48 computed = iteratee == null ? value : iteratee(value);
49
50 value = (comparator || value !== 0) ? value : 0;
51 if (isCommon && computed === computed) {
52 var valuesIndex = valuesLength;
53 while (valuesIndex--) {
54 if (values[valuesIndex] === computed) {
55 continue outer;
56 }
57 }
58 result.push(value);
59 }
60 else if (!includes(values, computed, comparator)) {
61 result.push(value);
62 }
63 }
64 return result;
65}
66
67module.exports = baseDifference;
Note: See TracBrowser for help on using the repository browser.