1 var arrayMap = require('./internal/arrayMap'),
2 baseIntersection = require('./internal/baseIntersection'),
3 last = require('./last'),
4 rest = require('./rest'),
5 toArrayLikeObject = require('./internal/toArrayLikeObject');
8 * This method is like `_.intersection` except that it accepts `comparator`
9 * which 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 shared values.
20 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
21 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
23 * _.intersectionWith(objects, others, _.isEqual);
24 * // => [{ 'x': 1, 'y': 2 }]
26 var intersectionWith = rest(function(arrays) {
27 var comparator = last(arrays),
28 mapped = arrayMap(arrays, toArrayLikeObject);
30 if (comparator === last(mapped)) {
31 comparator = undefined;
35 return (mapped.length && mapped[0] === arrays[0])
36 ? baseIntersection(mapped, undefined, comparator)
40 module.exports = intersectionWith;