source: node_modules/es-toolkit/dist/compat/array/xorWith.mjs@ a762898

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: 871 bytes
Line 
1import { differenceWith } from './differenceWith.mjs';
2import { intersectionWith } from './intersectionWith.mjs';
3import { last } from './last.mjs';
4import { unionWith } from './unionWith.mjs';
5import { windowed } from '../../array/windowed.mjs';
6import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
7
8function 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
21export { xorWith };
Note: See TracBrowser for help on using the repository browser.