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

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

Added visualizations

  • Property mode set to 100644
File size: 948 bytes
Line 
1import { differenceBy } from './differenceBy.mjs';
2import { intersectionBy } from './intersectionBy.mjs';
3import { last } from './last.mjs';
4import { unionBy } from './unionBy.mjs';
5import { windowed } from '../../array/windowed.mjs';
6import { identity } from '../../function/identity.mjs';
7import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
8import { iteratee } from '../util/iteratee.mjs';
9
10function xorBy(...values) {
11 const lastValue = last(values);
12 let mapper = identity;
13 if (!isArrayLikeObject(lastValue) && lastValue != null) {
14 mapper = iteratee(lastValue);
15 values = values.slice(0, -1);
16 }
17 const arrays = values.filter(isArrayLikeObject);
18 const union = unionBy(...arrays, mapper);
19 const intersections = windowed(arrays, 2).map(([arr1, arr2]) => intersectionBy(arr1, arr2, mapper));
20 return differenceBy(union, unionBy(...intersections, mapper), mapper);
21}
22
23export { xorBy };
Note: See TracBrowser for help on using the repository browser.