source: node_modules/es-toolkit/dist/compat/array/xor.mjs@ ba17441

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

Added visualizations

  • Property mode set to 100644
File size: 809 bytes
Line 
1import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
2import { toArray } from '../util/toArray.mjs';
3
4function xor(...arrays) {
5 const itemCounts = new Map();
6 for (let i = 0; i < arrays.length; i++) {
7 const array = arrays[i];
8 if (!isArrayLikeObject(array)) {
9 continue;
10 }
11 const itemSet = new Set(toArray(array));
12 for (const item of itemSet) {
13 if (!itemCounts.has(item)) {
14 itemCounts.set(item, 1);
15 }
16 else {
17 itemCounts.set(item, itemCounts.get(item) + 1);
18 }
19 }
20 }
21 const result = [];
22 for (const [item, count] of itemCounts) {
23 if (count === 1) {
24 result.push(item);
25 }
26 }
27 return result;
28}
29
30export { xor };
Note: See TracBrowser for help on using the repository browser.