es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
24 lines (21 loc) • 666 B
JavaScript
import { intersection as intersection$1 } from '../../array/intersection.mjs';
import { uniq } from '../../array/uniq.mjs';
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
function intersection(...arrays) {
if (arrays.length === 0) {
return [];
}
if (!isArrayLikeObject(arrays[0])) {
return [];
}
let result = uniq(Array.from(arrays[0]));
for (let i = 1; i < arrays.length; i++) {
const array = arrays[i];
if (!isArrayLikeObject(array)) {
return [];
}
result = intersection$1(result, Array.from(array));
}
return result;
}
export { intersection };