|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
871 bytes
|
| Line | |
|---|
| 1 | import { differenceWith } from './differenceWith.mjs';
|
|---|
| 2 | import { intersectionWith } from './intersectionWith.mjs';
|
|---|
| 3 | import { last } from './last.mjs';
|
|---|
| 4 | import { unionWith } from './unionWith.mjs';
|
|---|
| 5 | import { windowed } from '../../array/windowed.mjs';
|
|---|
| 6 | import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|---|
| 7 |
|
|---|
| 8 | function xorWith(...values) {
|
|---|
| 9 | const lastValue = last(values);
|
|---|
| 10 | let comparator = (a, b) => a === b;
|
|---|
| 11 | if (typeof lastValue === 'function') {
|
|---|
| 12 | comparator = lastValue;
|
|---|
| 13 | values = values.slice(0, -1);
|
|---|
| 14 | }
|
|---|
| 15 | const arrays = values.filter(isArrayLikeObject);
|
|---|
| 16 | const union = unionWith(...arrays, comparator);
|
|---|
| 17 | const intersections = windowed(arrays, 2).map(([arr1, arr2]) => intersectionWith(arr1, arr2, comparator));
|
|---|
| 18 | return differenceWith(union, unionWith(...intersections, comparator), comparator);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | export { xorWith };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.