UNPKG

1.1 kBJavaScriptView Raw
1var _includes =
2/*#__PURE__*/
3require("./internal/_includes");
4
5var _curry2 =
6/*#__PURE__*/
7require("./internal/_curry2");
8
9var _filter =
10/*#__PURE__*/
11require("./internal/_filter");
12
13var flip =
14/*#__PURE__*/
15require("./flip");
16
17var uniq =
18/*#__PURE__*/
19require("./uniq");
20/**
21 * Combines two lists into a set (i.e. no duplicates) composed of those
22 * elements common to both lists.
23 *
24 * @func
25 * @memberOf R
26 * @since v0.1.0
27 * @category Relation
28 * @sig [*] -> [*] -> [*]
29 * @param {Array} list1 The first list.
30 * @param {Array} list2 The second list.
31 * @return {Array} The list of elements found in both `list1` and `list2`.
32 * @see R.innerJoin
33 * @example
34 *
35 * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
36 */
37
38
39var intersection =
40/*#__PURE__*/
41_curry2(function intersection(list1, list2) {
42 var lookupList, filteredList;
43
44 if (list1.length > list2.length) {
45 lookupList = list1;
46 filteredList = list2;
47 } else {
48 lookupList = list2;
49 filteredList = list1;
50 }
51
52 return uniq(_filter(flip(_includes)(lookupList), filteredList));
53});
54
55module.exports = intersection;
\No newline at end of file