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
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var _filter =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_filter.js");
|
---|
| 8 |
|
---|
| 9 | var _Set =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./internal/_Set.js");
|
---|
| 12 |
|
---|
| 13 | var uniq =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./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 |
|
---|
| 35 | var 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 |
|
---|
| 47 | module.exports = intersection; |
---|
Note:
See
TracBrowser
for help on using the repository browser.