-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEverythingBeTrue.js
More file actions
42 lines (32 loc) · 908 Bytes
/
EverythingBeTrue.js
File metadata and controls
42 lines (32 loc) · 908 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
31
32
33
34
35
36
37
38
39
40
41
42
function truthCheck(collection, pre) {
var truthy = true;
var notTrue = [false, 0, "", null, undefined, NaN];
//Iterate over collection
collection.map(function(obj){
//If prop exists
if(obj[pre] !== undefined){
console.log(pre+': ' + obj[pre]);
//If typeof prop = number and is NaN
if(typeof obj[pre] == 'number' && isNaN(obj[pre])) {
//Set to false
truthy = false;
}
//Iterate of notTrue array
for (var i = 0; i < notTrue.length; i++){
//If obj prop matches item in notTrue array
if(obj[pre] === notTrue[i]){
//Set to false
truthy = false;
}
}
//Else if prop doesn't exist
} else {
console.log('doesnt exist');
//Set to false
truthy = false;
}
});
//Return true or false
return truthy;
}
truthCheck([{"single": "double"}, {"single": 'yes'}], "single");