|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
555 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | function intersectionBy(firstArr, secondArr, mapper) {
|
|---|
| 6 | const result = [];
|
|---|
| 7 | const mappedSecondSet = new Set(secondArr.map(mapper));
|
|---|
| 8 | for (let i = 0; i < firstArr.length; i++) {
|
|---|
| 9 | const item = firstArr[i];
|
|---|
| 10 | const mappedItem = mapper(item);
|
|---|
| 11 | if (mappedSecondSet.has(mappedItem)) {
|
|---|
| 12 | result.push(item);
|
|---|
| 13 | mappedSecondSet.delete(mappedItem);
|
|---|
| 14 | }
|
|---|
| 15 | }
|
|---|
| 16 | return result;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | exports.intersectionBy = intersectionBy;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.