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.
21 lines • 647 B
JavaScript
import { arrayIndex } from "./array-index.js";
import { fpIdentity } from "../../fp/impl/fp-identity.js";
/**
* @public
* Given two `ArrayLike`, provides the items common between them in an `Array`.
*
* @remarks
* See {@link arrayIntersect}.
*/
export function arrayIntersect(a, b, getComparisonValue = fpIdentity) {
const result = [];
const bIndex = 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;
}
//# sourceMappingURL=array-intersect.js.map