source: imaps-frontend/node_modules/lodash-es/intersectionBy.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import arrayMap from './_arrayMap.js';
2import baseIntersection from './_baseIntersection.js';
3import baseIteratee from './_baseIteratee.js';
4import baseRest from './_baseRest.js';
5import castArrayLikeObject from './_castArrayLikeObject.js';
6import last from './last.js';
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 they're compared. The order and references of result values are
12 * determined by the first array. The iteratee is invoked with one argument:
13 * (value).
14 *
15 * @static
16 * @memberOf _
17 * @since 4.0.0
18 * @category Array
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.
22 * @example
23 *
24 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
25 * // => [2.1]
26 *
27 * // The `_.property` iteratee shorthand.
28 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
29 * // => [{ 'x': 1 }]
30 */
31var intersectionBy = baseRest(function(arrays) {
32 var iteratee = last(arrays),
33 mapped = arrayMap(arrays, castArrayLikeObject);
34
35 if (iteratee === last(mapped)) {
36 iteratee = undefined;
37 } else {
38 mapped.pop();
39 }
40 return (mapped.length && mapped[0] === arrays[0])
41 ? baseIntersection(mapped, baseIteratee(iteratee, 2))
42 : [];
43});
44
45export default intersectionBy;
Note: See TracBrowser for help on using the repository browser.