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:
890 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry2 from "./internal/_curry2.js";
|
---|
| 2 | import _filter from "./internal/_filter.js";
|
---|
| 3 | import _Set from "./internal/_Set.js";
|
---|
| 4 | import uniq from "./uniq.js";
|
---|
| 5 | /**
|
---|
| 6 | * Combines two lists into a set (i.e. no duplicates) composed of those
|
---|
| 7 | * elements common to both lists.
|
---|
| 8 | *
|
---|
| 9 | * @func
|
---|
| 10 | * @memberOf R
|
---|
| 11 | * @since v0.1.0
|
---|
| 12 | * @category Relation
|
---|
| 13 | * @sig [*] -> [*] -> [*]
|
---|
| 14 | * @param {Array} list1 The first list.
|
---|
| 15 | * @param {Array} list2 The second list.
|
---|
| 16 | * @return {Array} The list of elements found in both `list1` and `list2`.
|
---|
| 17 | * @see R.innerJoin
|
---|
| 18 | * @example
|
---|
| 19 | *
|
---|
| 20 | * R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | var intersection =
|
---|
| 24 | /*#__PURE__*/
|
---|
| 25 | _curry2(function intersection(list1, list2) {
|
---|
| 26 | var toKeep = new _Set();
|
---|
| 27 |
|
---|
| 28 | for (var i = 0; i < list1.length; i += 1) {
|
---|
| 29 | toKeep.add(list1[i]);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | return uniq(_filter(toKeep.has.bind(toKeep), list2));
|
---|
| 33 | });
|
---|
| 34 |
|
---|
| 35 | export default intersection; |
---|
Note:
See
TracBrowser
for help on using the repository browser.