@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
16 lines (12 loc) • 573 B
text/typescript
import { findIndex } from '../../utils/lang';
export function partOfSetMatcherContext(ruleAttr: string[]) {
return function partOfMatcher(runtimeAttr: string[]): boolean {
// To be part of the length should be minor or equal.
let isPartOf = runtimeAttr.length <= ruleAttr.length;
for (let i = 0; i < runtimeAttr.length && isPartOf; i++) {
// If the length says is possible, we iterate until we prove otherwise or we check all elements.
if (findIndex(ruleAttr, e => e === runtimeAttr[i]) < 0) isPartOf = false;
}
return isPartOf;
};
}