source: node_modules/es-toolkit/dist/compat/array/intersectionBy.js@ ba17441

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

Added visualizations

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const intersectionBy$1 = require('../../array/intersectionBy.js');
6const last = require('../../array/last.js');
7const uniq = require('../../array/uniq.js');
8const identity = require('../../function/identity.js');
9const property = require('../object/property.js');
10const isArrayLikeObject = require('../predicate/isArrayLikeObject.js');
11
12function 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
40exports.intersectionBy = intersectionBy;
Note: See TracBrowser for help on using the repository browser.