mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/intersection.js
|
|
|
|
|
|
import _includes from './internal/_includes.js';
|
|
import _curry2 from './internal/_curry2.js';
|
|
import _filter from './internal/_filter.js';
|
|
import flip from './flip.js';
|
|
import uniq from './uniq.js';
|
|
|
|
|
|
/**
|
|
* Combines two lists into a set (i.e. no duplicates) composed of those
|
|
* elements common to both lists.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.1.0
|
|
* @category Relation
|
|
* @sig [*] -> [*] -> [*]
|
|
* @param {Array} list1 The first list.
|
|
* @param {Array} list2 The second list.
|
|
* @return {Array} The list of elements found in both `list1` and `list2`.
|
|
* @see R.innerJoin
|
|
* @example
|
|
*
|
|
* R.intersection([1,2,3,4], [7,6,5,4,3]); //=> [4, 3]
|
|
*/
|
|
var intersection = _curry2(function intersection(list1, list2) {
|
|
var lookupList, filteredList;
|
|
if (list1.length > list2.length) {
|
|
lookupList = list1;
|
|
filteredList = list2;
|
|
} else {
|
|
lookupList = list2;
|
|
filteredList = list1;
|
|
}
|
|
return uniq(_filter(flip(_includes)(lookupList), filteredList));
|
|
});
|
|
export default intersection;
|