2c9e0d33079367f442380669aa654dc62bd8bf2f
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / intersectionBy.js
1 var arrayMap = require('./_arrayMap'),
2     baseIntersection = require('./_baseIntersection'),
3     baseIteratee = require('./_baseIteratee'),
4     last = require('./last'),
5     rest = require('./rest'),
6     toArrayLikeObject = require('./_toArrayLikeObject');
7
8 /**
9  * This method is like `_.intersection` except that it accepts `iteratee`
10  * which is invoked for each element of each `arrays` to generate the criterion
11  * by which 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 shared values.
19  * @example
20  *
21  * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
22  * // => [2.1]
23  *
24  * // The `_.property` iteratee shorthand.
25  * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
26  * // => [{ 'x': 1 }]
27  */
28 var intersectionBy = rest(function(arrays) {
29   var iteratee = last(arrays),
30       mapped = arrayMap(arrays, toArrayLikeObject);
31
32   if (iteratee === last(mapped)) {
33     iteratee = undefined;
34   } else {
35     mapped.pop();
36   }
37   return (mapped.length && mapped[0] === arrays[0])
38     ? baseIntersection(mapped, baseIteratee(iteratee))
39     : [];
40 });
41
42 module.exports = intersectionBy;