|
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 | |
|---|
| 1 | import { differenceBy } from './differenceBy.mjs';
|
|---|
| 2 | import { intersectionBy } from './intersectionBy.mjs';
|
|---|
| 3 | import { last } from './last.mjs';
|
|---|
| 4 | import { unionBy } from './unionBy.mjs';
|
|---|
| 5 | import { windowed } from '../../array/windowed.mjs';
|
|---|
| 6 | import { identity } from '../../function/identity.mjs';
|
|---|
| 7 | import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|---|
| 8 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 9 |
|
|---|
| 10 | function 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 |
|
|---|
| 23 | export { xorBy };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.