1 var baseFlatten = require('./internal/baseFlatten'),
2 baseUniq = require('./internal/baseUniq'),
3 isArrayLikeObject = require('./isArrayLikeObject'),
4 last = require('./last'),
5 rest = require('./rest');
8 * This method is like `_.union` except that it accepts `comparator` which
9 * is invoked to compare elements of `arrays`. The comparator is invoked
10 * with two arguments: (arrVal, othVal).
15 * @param {...Array} [arrays] The arrays to inspect.
16 * @param {Function} [comparator] The comparator invoked per element.
17 * @returns {Array} Returns the new array of combined values.
20 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
21 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
23 * _.unionWith(objects, others, _.isEqual);
24 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
26 var unionWith = rest(function(arrays) {
27 var comparator = last(arrays);
28 if (isArrayLikeObject(comparator)) {
29 comparator = undefined;
31 return baseUniq(baseFlatten(arrays, false, true), undefined, comparator);
34 module.exports = unionWith;