Skip to content

Commit 322c7ff

Browse files
committed
Made 30 easier
1 parent 455bf3e commit 322c7ff

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/06-challenges/30-form-validator.problem.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import { expect, it } from "vitest";
22

3-
const makeFormValidatorFactory = (validators: unknown) => {};
3+
const makeFormValidatorFactory = (validators: unknown) => (config: unknown) => {
4+
return (values: unknown) => {
5+
const errors = {} as any;
6+
7+
for (const key in config) {
8+
for (const validator of config[key]) {
9+
const error = validators[validator](values[key]);
10+
if (error) {
11+
errors[key] = error;
12+
break;
13+
}
14+
}
15+
}
16+
17+
return errors;
18+
};
19+
};
420

521
const createFormValidator = makeFormValidatorFactory({
622
required: (value) => {

0 commit comments

Comments
 (0)