|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const last = require('./last.js');
|
|---|
| 6 | const intersectionWith$1 = require('../../array/intersectionWith.js');
|
|---|
| 7 | const uniq = require('./uniq.js');
|
|---|
| 8 | const isEqualsSameValueZero = require('../../_internal/isEqualsSameValueZero.js');
|
|---|
| 9 |
|
|---|
| 10 | function intersectionWith(firstArr, ...otherArrs) {
|
|---|
| 11 | if (firstArr == null) {
|
|---|
| 12 | return [];
|
|---|
| 13 | }
|
|---|
| 14 | const _comparator = last.last(otherArrs);
|
|---|
| 15 | let comparator = isEqualsSameValueZero.isEqualsSameValueZero;
|
|---|
| 16 | let uniq$1 = uniq.uniq;
|
|---|
| 17 | if (typeof _comparator === 'function') {
|
|---|
| 18 | comparator = _comparator;
|
|---|
| 19 | uniq$1 = uniqPreserve0;
|
|---|
| 20 | otherArrs.pop();
|
|---|
| 21 | }
|
|---|
| 22 | let result = uniq$1(Array.from(firstArr));
|
|---|
| 23 | for (let i = 0; i < otherArrs.length; ++i) {
|
|---|
| 24 | const otherArr = otherArrs[i];
|
|---|
| 25 | if (otherArr == null) {
|
|---|
| 26 | return [];
|
|---|
| 27 | }
|
|---|
| 28 | result = intersectionWith$1.intersectionWith(result, Array.from(otherArr), comparator);
|
|---|
| 29 | }
|
|---|
| 30 | return result;
|
|---|
| 31 | }
|
|---|
| 32 | function uniqPreserve0(arr) {
|
|---|
| 33 | const result = [];
|
|---|
| 34 | const added = new Set();
|
|---|
| 35 | for (let i = 0; i < arr.length; i++) {
|
|---|
| 36 | const item = arr[i];
|
|---|
| 37 | if (added.has(item)) {
|
|---|
| 38 | continue;
|
|---|
| 39 | }
|
|---|
| 40 | result.push(item);
|
|---|
| 41 | added.add(item);
|
|---|
| 42 | }
|
|---|
| 43 | return result;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | exports.intersectionWith = intersectionWith;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.