source: node_modules/es-toolkit/dist/compat/array/intersectionWith.mjs@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import { last } from './last.mjs';
2import { intersectionWith as intersectionWith$1 } from '../../array/intersectionWith.mjs';
3import { uniq } from './uniq.mjs';
4import { isEqualsSameValueZero } from '../../_internal/isEqualsSameValueZero.mjs';
5
6function intersectionWith(firstArr, ...otherArrs) {
7 if (firstArr == null) {
8 return [];
9 }
10 const _comparator = last(otherArrs);
11 let comparator = isEqualsSameValueZero;
12 let uniq$1 = uniq;
13 if (typeof _comparator === 'function') {
14 comparator = _comparator;
15 uniq$1 = uniqPreserve0;
16 otherArrs.pop();
17 }
18 let result = uniq$1(Array.from(firstArr));
19 for (let i = 0; i < otherArrs.length; ++i) {
20 const otherArr = otherArrs[i];
21 if (otherArr == null) {
22 return [];
23 }
24 result = intersectionWith$1(result, Array.from(otherArr), comparator);
25 }
26 return result;
27}
28function uniqPreserve0(arr) {
29 const result = [];
30 const added = new Set();
31 for (let i = 0; i < arr.length; i++) {
32 const item = arr[i];
33 if (added.has(item)) {
34 continue;
35 }
36 result.push(item);
37 added.add(item);
38 }
39 return result;
40}
41
42export { intersectionWith };
Note: See TracBrowser for help on using the repository browser.