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