1 var arrayMap = require('./_arrayMap'),
2 baseIntersection = require('./_baseIntersection'),
3 baseIteratee = require('./_baseIteratee'),
4 baseRest = require('./_baseRest'),
5 castArrayLikeObject = require('./_castArrayLikeObject'),
6 last = require('./last');
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 they're compared. The order and references of result values are
12 * determined by the first array. The iteratee is invoked with one argument:
19 * @param {...Array} [arrays] The arrays to inspect.
20 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
21 * @returns {Array} Returns the new array of intersecting values.
24 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
27 * // The `_.property` iteratee shorthand.
28 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
31 var intersectionBy = baseRest(function(arrays) {
32 var iteratee = last(arrays),
33 mapped = arrayMap(arrays, castArrayLikeObject);
35 if (iteratee === last(mapped)) {
40 return (mapped.length && mapped[0] === arrays[0])
41 ? baseIntersection(mapped, baseIteratee(iteratee, 2))
45 module.exports = intersectionBy;