Hello. I can’t seem to figure out how come in my algorithm the if statement passes everything as true. Can someone please help me with this code?
function truthCheck(collection, pre) {
var truthCount = 0;
for(var i = 0; i<collection.length; i++) {
if (collection[i].hasOwnProperty(pre) === true) {
truthCount +=1;
}
}
if (truthCount == collection.length) {
return true;
} else {
return false;
}
}
truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age");
no matter what the argument that’s passed in, truthCount
always ends up equalling collection.length
.