forked from Teavaro/pair-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
30 lines (29 loc) · 705 Bytes
/
Copy pathvalidate.js
File metadata and controls
30 lines (29 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function validate(validationObject, data) {
/* Implementation intructions provided during the pair programming */
if (
!validationObject ||
validationObject.length != Object.keys(data).length
) {
return false;
}
let response = false;
for (const key in data) {
response = false;
if (Object.hasOwnProperty.call(data, key)) {
const element = data[key];
validationObject.forEach((validator) => {
if (
key == validator.fieldName &&
typeof element == validator.fieldType
) {
response = true;
}
});
}
if (!response) {
return response;
}
}
return response;
}
module.exports = validate;