|
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:
927 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isArrayLikeObject = require('../predicate/isArrayLikeObject.js');
|
|---|
| 6 | const toArray = require('../util/toArray.js');
|
|---|
| 7 |
|
|---|
| 8 | function xor(...arrays) {
|
|---|
| 9 | const itemCounts = new Map();
|
|---|
| 10 | for (let i = 0; i < arrays.length; i++) {
|
|---|
| 11 | const array = arrays[i];
|
|---|
| 12 | if (!isArrayLikeObject.isArrayLikeObject(array)) {
|
|---|
| 13 | continue;
|
|---|
| 14 | }
|
|---|
| 15 | const itemSet = new Set(toArray.toArray(array));
|
|---|
| 16 | for (const item of itemSet) {
|
|---|
| 17 | if (!itemCounts.has(item)) {
|
|---|
| 18 | itemCounts.set(item, 1);
|
|---|
| 19 | }
|
|---|
| 20 | else {
|
|---|
| 21 | itemCounts.set(item, itemCounts.get(item) + 1);
|
|---|
| 22 | }
|
|---|
| 23 | }
|
|---|
| 24 | }
|
|---|
| 25 | const result = [];
|
|---|
| 26 | for (const [item, count] of itemCounts) {
|
|---|
| 27 | if (count === 1) {
|
|---|
| 28 | result.push(item);
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 | return result;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | exports.xor = xor;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.