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');
8 /* Built-in method references for those with the same name as other `lodash` methods. */
9 var nativeMin = Math.min;
12 * The base implementation of methods like `_.intersection`, without support
13 * for iteratee shorthands, that accepts an array of arrays to inspect.
16 * @param {Array} arrays The arrays to inspect.
17 * @param {Function} [iteratee] The iteratee invoked per element.
18 * @param {Function} [comparator] The comparator invoked per element.
19 * @returns {Array} Returns the new array of shared values.
21 function baseIntersection(arrays, iteratee, comparator) {
22 var includes = comparator ? arrayIncludesWith : arrayIncludes,
23 length = arrays[0].length,
24 othLength = arrays.length,
26 caches = Array(othLength),
31 var array = arrays[othIndex];
32 if (othIndex && iteratee) {
33 array = arrayMap(array, baseUnary(iteratee));
35 maxLength = nativeMin(array.length, maxLength);
36 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
37 ? new SetCache(othIndex && array)
46 while (++index < length && result.length < maxLength) {
47 var value = array[index],
48 computed = iteratee ? iteratee(value) : value;
50 value = (comparator || value !== 0) ? value : 0;
52 ? cacheHas(seen, computed)
53 : includes(result, computed, comparator)
57 var cache = caches[othIndex];
59 ? cacheHas(cache, computed)
60 : includes(arrays[othIndex], computed, comparator))
74 module.exports = baseIntersection;