source: node_modules/ramda/src/intersection.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 964 bytes
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var _filter =
6/*#__PURE__*/
7require("./internal/_filter.js");
8
9var _Set =
10/*#__PURE__*/
11require("./internal/_Set.js");
12
13var uniq =
14/*#__PURE__*/
15require("./uniq.js");
16/**
17 * Combines two lists into a set (i.e. no duplicates) composed of those
18 * elements common to both lists.
19 *
20 * @func
21 * @memberOf R
22 * @since v0.1.0
23 * @category Relation
24 * @sig [*] -> [*] -> [*]
25 * @param {Array} list1 The first list.
26 * @param {Array} list2 The second list.
27 * @return {Array} The list of elements found in both `list1` and `list2`.
28 * @see R.innerJoin
29 * @example
30 *
31 * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
32 */
33
34
35var intersection =
36/*#__PURE__*/
37_curry2(function intersection(list1, list2) {
38 var toKeep = new _Set();
39
40 for (var i = 0; i < list1.length; i += 1) {
41 toKeep.add(list1[i]);
42 }
43
44 return uniq(_filter(toKeep.has.bind(toKeep), list2));
45});
46
47module.exports = intersection;
Note: See TracBrowser for help on using the repository browser.