-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtruthCheck.js
More file actions
19 lines (13 loc) · 845 Bytes
/
truthCheck.js
File metadata and controls
19 lines (13 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
function truthCheck(collection, pre) {
// The every() method tests whether all elements in the array pass the test implemented by the provided function.
// iterate over the objects from the collection array and check every value of every key that's inside
// basically it will check every key-value pair from the collection array
return collection.every(function(obj) {
// check if the objects "pre" key has a non-falsy object
// if it passes the test it will return true, otherwise it will return false
//console.log(obj[pre]);
return obj[pre];
});
}
truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastFoward", "onBoat": true}], "onBoat");