Skip to content

Commit 555bf85

Browse files
committed
patch(n4s): replace array with counter in oneOf
1 parent 28db6c7 commit 555bf85

File tree

1 file changed

+6
-6
lines changed
  • packages/n4s/src/plugins/compounds

1 file changed

+6
-6
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
import { equals } from 'equals';
12
import type { Lazy } from 'genEnforceLazy';
2-
import { lengthEquals } from 'lengthEquals';
3-
import { longerThan } from 'longerThan';
3+
import { greaterThan } from 'greaterThan';
44
import ruleReturn, { RuleDetailedResult } from 'ruleReturn';
55
import runLazyRule from 'runLazyRule';
66

77
const REQUIRED_COUNT = 1;
88

99
export function oneOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult {
10-
const passing: RuleDetailedResult[] = [];
10+
let passingCount = 0;
1111
rules.some(rule => {
1212
const res = runLazyRule(rule, value);
1313

1414
if (res.pass) {
15-
passing.push(res);
15+
passingCount++;
1616
}
1717

18-
if (longerThan(passing, REQUIRED_COUNT)) {
18+
if (greaterThan(passingCount, REQUIRED_COUNT)) {
1919
return false;
2020
}
2121
});
2222

23-
return ruleReturn(lengthEquals(passing, REQUIRED_COUNT));
23+
return ruleReturn(equals(passingCount, REQUIRED_COUNT));
2424
}

0 commit comments

Comments
 (0)