-
Notifications
You must be signed in to change notification settings - Fork 0
/
TruthCheck.js
58 lines (41 loc) · 1.14 KB
/
TruthCheck.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function truthCheck(collection, pre) {
// Is everyone being true?
var result = true;
for (let i = 0; i < collection.length; i++) {
if (!collection[i].hasOwnProperty(pre)) {
result = false;
console.log('hasOwnProperty')
}
else if (collection[i][pre] == "") {
result = false;
console.log('empty string')
}
else if (collection[i][pre] == 0) {
result = false;
console.log('zero')
}
else if (collection[i][pre] == {}) {
result = false;
console.log('empty object')
}
else if (collection[i][pre] == []) {
result = false;
console.log('empty array')
}
else if (collection[i][pre] == false) {
result = false;
console.log('false')
}
else if (collection[i][pre] == undefined) {
result = false;
console.log('undefined!')
}
else if (Number.isNaN(collection[i][pre])) {
result = false;
console.log('NaN!')
}
}
console.log(result)
return result
}
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")