You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 line
953 B

4 年之前
  1. var arrayMap = require('./_arrayMap'),
  2. baseIntersection = require('./_baseIntersection'),
  3. baseRest = require('./_baseRest'),
  4. castArrayLikeObject = require('./_castArrayLikeObject');
  5. /**
  6. * Creates an array of unique values that are included in all given arrays
  7. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8. * for equality comparisons. The order and references of result values are
  9. * determined by the first array.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 0.1.0
  14. * @category Array
  15. * @param {...Array} [arrays] The arrays to inspect.
  16. * @returns {Array} Returns the new array of intersecting values.
  17. * @example
  18. *
  19. * _.intersection([2, 1], [2, 3]);
  20. * // => [2]
  21. */
  22. var intersection = baseRest(function(arrays) {
  23. var mapped = arrayMap(arrays, castArrayLikeObject);
  24. return (mapped.length && mapped[0] === arrays[0])
  25. ? baseIntersection(mapped)
  26. : [];
  27. });
  28. module.exports = intersection;