Created
September 16, 2016 02:16
-
-
Save rickMcGavin/9732f6e5a662bf36a57015077cb707ae to your computer and use it in GitHub Desktop.
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) { | |
var count = 0; | |
// loop through each object in the collection array | |
collection.forEach(function(element, index){ | |
// loop through each key in the object | |
for (var key in element) { | |
// iterate through the object's properties | |
if (element.hasOwnProperty(key)) | |
if (!element[pre]) | |
return false; // return false if any of the object's properties are falsy | |
// check if key is equal to the second argument of the function | |
if (key === pre) { | |
count += 1; | |
} | |
} | |
}); | |
// if the length of the collection is not equal to the count return false | |
if (collection.length !== count) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment