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