UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

35 lines (34 loc) 1.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.intersection = void 0; const baseIntersection_1 = __importDefault(require("./.internal/baseIntersection")); const castArrayLikeObject_1 = __importDefault(require("./.internal/castArrayLikeObject")); const arrayMap_1 = __importDefault(require("./.internal/arrayMap")); /** * Creates an array of unique values that are included in all given arrays * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) * for equality comparisons. The order and references of result values are * determined by the first array. * * @since 5.11.0 * @category Array * @param arrays The arrays to inspect. * @returns Returns the new array of intersecting values. * @example * * ```js * intersection([2, 1], [2, 3]) * // => [2] * ``` */ function intersection(...arrays) { const mapped = (0, arrayMap_1.default)(arrays, castArrayLikeObject_1.default); return (mapped.length && mapped[0] === arrays[0]) ? (0, baseIntersection_1.default)(mapped) : []; } exports.intersection = intersection; exports.default = intersection;