union.js 716 B

123456789101112131415161718192021222324
  1. var baseFlatten = require('../internal/baseFlatten'),
  2. baseUniq = require('../internal/baseUniq'),
  3. restParam = require('../function/restParam');
  4. /**
  5. * Creates an array of unique values, in order, from all of the provided arrays
  6. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  7. * for equality comparisons.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @category Array
  12. * @param {...Array} [arrays] The arrays to inspect.
  13. * @returns {Array} Returns the new array of combined values.
  14. * @example
  15. *
  16. * _.union([1, 2], [4, 2], [2, 1]);
  17. * // => [1, 2, 4]
  18. */
  19. var union = restParam(function(arrays) {
  20. return baseUniq(baseFlatten(arrays, false, true));
  21. });
  22. module.exports = union;