Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / baseIntersection.js
1 var 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 /**
9  * The base implementation of methods like `_.intersection`, without support
10  * for iteratee shorthands, that accepts an array of arrays to inspect.
11  *
12  * @private
13  * @param {Array} arrays The arrays to inspect.
14  * @param {Function} [iteratee] The iteratee invoked per element.
15  * @param {Function} [comparator] The comparator invoked per element.
16  * @returns {Array} Returns the new array of shared values.
17  */
18 function baseIntersection(arrays, iteratee, comparator) {
19   var includes = comparator ? arrayIncludesWith : arrayIncludes,
20       othLength = arrays.length,
21       othIndex = othLength,
22       caches = Array(othLength),
23       result = [];
24
25   while (othIndex--) {
26     var array = arrays[othIndex];
27     if (othIndex && iteratee) {
28       array = arrayMap(array, baseUnary(iteratee));
29     }
30     caches[othIndex] = !comparator && (iteratee || array.length >= 120)
31       ? new SetCache(othIndex && array)
32       : undefined;
33   }
34   array = arrays[0];
35
36   var index = -1,
37       length = array.length,
38       seen = caches[0];
39
40   outer:
41   while (++index < length) {
42     var value = array[index],
43         computed = iteratee ? iteratee(value) : value;
44
45     if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator))) {
46       var othIndex = othLength;
47       while (--othIndex) {
48         var cache = caches[othIndex];
49         if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator))) {
50           continue outer;
51         }
52       }
53       if (seen) {
54         seen.push(computed);
55       }
56       result.push(value);
57     }
58   }
59   return result;
60 }
61
62 module.exports = baseIntersection;