UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

25 lines 844 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayIntersect = void 0; const array_index_js_1 = require("./array-index.js"); const fp_identity_js_1 = require("../../fp/impl/fp-identity.js"); /** * @public * Given two `ArrayLike`, provides the items common between them in an `Array`. * * @remarks * See {@link arrayIntersect}. */ function arrayIntersect(a, b, getComparisonValue = fp_identity_js_1.fpIdentity) { const result = []; const bIndex = (0, array_index_js_1.arrayIndex)(b, getComparisonValue); for (let i = 0, iEnd = a.length; i < iEnd; ++i) { const item = a[i]; if (bIndex.has(getComparisonValue(item, i))) { result.push(item); } } return result; } exports.arrayIntersect = arrayIntersect; //# sourceMappingURL=array-intersect.js.map