react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / array / intersection.js
80742 viewsvar baseIndexOf = require('../internal/baseIndexOf'),1cacheIndexOf = require('../internal/cacheIndexOf'),2createCache = require('../internal/createCache'),3isArrayLike = require('../internal/isArrayLike'),4restParam = require('../function/restParam');56/**7* Creates an array of unique values that are included in all of the provided8* arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)9* for equality comparisons.10*11* @static12* @memberOf _13* @category Array14* @param {...Array} [arrays] The arrays to inspect.15* @returns {Array} Returns the new array of shared values.16* @example17* _.intersection([1, 2], [4, 2], [2, 1]);18* // => [2]19*/20var intersection = restParam(function(arrays) {21var othLength = arrays.length,22othIndex = othLength,23caches = Array(length),24indexOf = baseIndexOf,25isCommon = true,26result = [];2728while (othIndex--) {29var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];30caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;31}32var array = arrays[0],33index = -1,34length = array ? array.length : 0,35seen = caches[0];3637outer:38while (++index < length) {39value = array[index];40if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {41var othIndex = othLength;42while (--othIndex) {43var cache = caches[othIndex];44if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {45continue outer;46}47}48if (seen) {49seen.push(value);50}51result.push(value);52}53}54return result;55});5657module.exports = intersection;585960