Skip to content

Instantly share code, notes, and snippets.

@rickMcGavin
Created September 16, 2016 02:16
Show Gist options
  • Save rickMcGavin/9732f6e5a662bf36a57015077cb707ae to your computer and use it in GitHub Desktop.
Save rickMcGavin/9732f6e5a662bf36a57015077cb707ae to your computer and use it in GitHub Desktop.
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