everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
17 lines (16 loc) • 523 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayIntersections = void 0;
/**
* Finds common elements across multiple arrays.
* @author @dailker
* @template T
* @param {...T[][]} arrays - Arrays to intersect.
* @returns {T[]} Array of common elements.
*/
function arrayIntersections(...arrays) {
if (arrays.length === 0)
return [];
return arrays.reduce((a, b) => a.filter(x => b.includes(x)));
}
exports.arrayIntersections = arrayIntersections;