source: node_modules/es-toolkit/dist/compat/array/intersectionBy.mjs

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

Added visualizations

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[a762898]1import { intersectionBy as intersectionBy$1 } from '../../array/intersectionBy.mjs';
2import { last } from '../../array/last.mjs';
3import { uniq } from '../../array/uniq.mjs';
4import { identity } from '../../function/identity.mjs';
5import { property } from '../object/property.mjs';
6import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
7
8function 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
36export { intersectionBy };
Note: See TracBrowser for help on using the repository browser.