1eca729069e44a42eec92bd8f895fa1fa24a8868
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / unionWith.js
1 var baseFlatten = require('./_baseFlatten'),
2     baseUniq = require('./_baseUniq'),
3     isArrayLikeObject = require('./isArrayLikeObject'),
4     last = require('./last'),
5     rest = require('./rest');
6
7 /**
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).
11  *
12  * @static
13  * @memberOf _
14  * @category Array
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.
18  * @example
19  *
20  * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
21  * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
22  *
23  * _.unionWith(objects, others, _.isEqual);
24  * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
25  */
26 var unionWith = rest(function(arrays) {
27   var comparator = last(arrays);
28   if (isArrayLikeObject(comparator)) {
29     comparator = undefined;
30   }
31   return baseUniq(baseFlatten(arrays, false, true), undefined, comparator);
32 });
33
34 module.exports = unionWith;