| [a762898] | 1 | import { intersectionBy as intersectionBy$1 } from '../../array/intersectionBy.mjs';
|
|---|
| 2 | import { last } from '../../array/last.mjs';
|
|---|
| 3 | import { uniq } from '../../array/uniq.mjs';
|
|---|
| 4 | import { identity } from '../../function/identity.mjs';
|
|---|
| 5 | import { property } from '../object/property.mjs';
|
|---|
| 6 | import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|---|
| 7 |
|
|---|
| 8 | function intersectionBy(array, ...values) {
|
|---|
| 9 | if (!isArrayLikeObject(array)) {
|
|---|
| 10 | return [];
|
|---|
| 11 | }
|
|---|
| 12 | const lastValue = last(values);
|
|---|
| 13 | if (lastValue === undefined) {
|
|---|
| 14 | return Array.from(array);
|
|---|
| 15 | }
|
|---|
| 16 | let result = uniq(Array.from(array));
|
|---|
| 17 | const count = isArrayLikeObject(lastValue) ? values.length : values.length - 1;
|
|---|
| 18 | for (let i = 0; i < count; ++i) {
|
|---|
| 19 | const value = values[i];
|
|---|
| 20 | if (!isArrayLikeObject(value)) {
|
|---|
| 21 | return [];
|
|---|
| 22 | }
|
|---|
| 23 | if (isArrayLikeObject(lastValue)) {
|
|---|
| 24 | result = intersectionBy$1(result, Array.from(value), identity);
|
|---|
| 25 | }
|
|---|
| 26 | else if (typeof lastValue === 'function') {
|
|---|
| 27 | result = intersectionBy$1(result, Array.from(value), value => lastValue(value));
|
|---|
| 28 | }
|
|---|
| 29 | else if (typeof lastValue === 'string') {
|
|---|
| 30 | result = intersectionBy$1(result, Array.from(value), property(lastValue));
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | return result;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | export { intersectionBy };
|
|---|