-
Notifications
You must be signed in to change notification settings - Fork 0
/
schematizer5
40 lines (35 loc) · 1.07 KB
/
schematizer5
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
31
32
33
34
35
36
37
38
39
40
Finally, lettuce refactor the code taking advantage of javascript for loops' ability to iterate through objects:
if (property is not in object) {
if (property is right type) {
message += 'all good'
} else {
property = fallback
message += 'type was bad, replaced'
}
} else {
property = fallback
message += 'prop was absent, fallback inserted'
}
if (property is not in schema) {
message += 'extra property detected'
}
----------------------------------------------------------------
for (property in object) {
if (property is in schema) {
if (property is right type) {
message += 'all good'
} else {
property = fallback
message += 'type was bad, replaced'
}
} else {
property = fallback
message += 'prop was absent, fallback inserted'
}
if (property is not in schema) {
message += 'extra property detected'
}
}
// however, this code will not check to see if a property is missing, only that it is correct if it is there. so...
----------------------------------------------------------------
// that's up to you to fix