Created
October 5, 2018 05:53
-
-
Save jepras/53824217b755bc9684374ae3e9905515 to your computer and use it in GitHub Desktop.
Used hasOwnProperty to check collection objects had the second argument in them to increase a counter. Finally check counter vs length to check if all values were true.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function truthCheck(collection, pre) { | |
// Is everyone being true? | |
var counter = 0; | |
for (let c in collection) { | |
if (collection[c].hasOwnProperty(pre) && Boolean(collection[c][pre])) { | |
counter++; | |
} | |
} | |
if (counter == collection.length) { | |
return true; | |
} | |
return false; | |
} | |
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment