Sha256: 36705499dd6b6da8b8a977dfa689ef5fe83ecf9156fcbc74d1ba8a70f2632d7a

Contents?: true

Size: 1.72 KB

Versions: 153

Compression:

Stored size: 1.72 KB

Contents

var baseIndexOf = require('../internal/baseIndexOf'),
    cacheIndexOf = require('../internal/cacheIndexOf'),
    createCache = require('../internal/createCache'),
    isArrayLike = require('../internal/isArrayLike'),
    restParam = require('../function/restParam');

/**
 * Creates an array of unique values that are included in all of the provided
 * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
 * for equality comparisons.
 *
 * @static
 * @memberOf _
 * @category Array
 * @param {...Array} [arrays] The arrays to inspect.
 * @returns {Array} Returns the new array of shared values.
 * @example
 * _.intersection([1, 2], [4, 2], [2, 1]);
 * // => [2]
 */
var intersection = restParam(function(arrays) {
  var othLength = arrays.length,
      othIndex = othLength,
      caches = Array(length),
      indexOf = baseIndexOf,
      isCommon = true,
      result = [];

  while (othIndex--) {
    var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
    caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
  }
  var array = arrays[0],
      index = -1,
      length = array ? array.length : 0,
      seen = caches[0];

  outer:
  while (++index < length) {
    value = array[index];
    if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
      var othIndex = othLength;
      while (--othIndex) {
        var cache = caches[othIndex];
        if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
          continue outer;
        }
      }
      if (seen) {
        seen.push(value);
      }
      result.push(value);
    }
  }
  return result;
});

module.exports = intersection;

Version data entries

153 entries across 80 versions & 8 rubygems

Version Path
trusty-festivity-extension-2.3.12 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.12 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.11g node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.11g node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.10 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.10 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.9 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.9 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.8 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.8 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.7 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.7 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.6 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.6 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.5 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.5 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.4 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.4 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.3 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/intersection.js
trusty-festivity-extension-2.3.3 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/intersection.js