26050bcd4f785fb0537d0a2a348273e161a89e03
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / unionBy.js
1 var baseFlatten = require('./_baseFlatten'),
2     baseIteratee = require('./_baseIteratee'),
3     baseUniq = require('./_baseUniq'),
4     isArrayLikeObject = require('./isArrayLikeObject'),
5     last = require('./last'),
6     rest = require('./rest');
7
8 /**
9  * This method is like `_.union` except that it accepts `iteratee` which is
10  * invoked for each element of each `arrays` to generate the criterion by which
11  * uniqueness is computed. The iteratee is invoked with one argument: (value).
12  *
13  * @static
14  * @memberOf _
15  * @category Array
16  * @param {...Array} [arrays] The arrays to inspect.
17  * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
18  * @returns {Array} Returns the new array of combined values.
19  * @example
20  *
21  * _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
22  * // => [2.1, 1.2, 4.3]
23  *
24  * // The `_.property` iteratee shorthand.
25  * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
26  * // => [{ 'x': 1 }, { 'x': 2 }]
27  */
28 var unionBy = rest(function(arrays) {
29   var iteratee = last(arrays);
30   if (isArrayLikeObject(iteratee)) {
31     iteratee = undefined;
32   }
33   return baseUniq(baseFlatten(arrays, false, true), baseIteratee(iteratee));
34 });
35
36 module.exports = unionBy;