Gerwyn
June 12, 2019, 4:27am
1
hi guys i can’t seem to solve this challenge completely. i have 3 requirements unticked and i can’t seem to diagnose the problem. help please!
function truthCheck(collection, pre) {
// Is everyone being true?
for ( let i = 0; i < collection.length; i++) {
let allProperties = Object.keys(collection[i])
for (let property in allProperties) {
if ((!collection[i].hasOwnProperty(pre)) || allProperties[pre] !== true ) {
return false;
}
}
}
return true;
}
console.log(truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"));
Gerwyn
June 12, 2019, 5:02am
3
ooo thank you i solved it… i’ve taken out what i didn’t need to use as well
function truthCheck(collection, pre) {
// Is everyone being true?
for ( let i = 0; i < collection.length; i++) {
if ((!collection[i].hasOwnProperty(pre)) || !collection[i][pre] ) {
return false;
}
}
return true;
}
console.log(truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"));
Gerwyn
June 12, 2019, 5:08am
5
mhm let me think… so this alone checks if its truthy --> !collection[i][pre]
It doesn’t check only if its value is truthy, it also checks if the “pre” property is existent? because if “pre” is existent then its considered truthy? correct if im wrong because its able to substitute “.hasOwnProperty”
Gerwyn
June 12, 2019, 5:13am
7
oh yeah that’s a good way to put it lol i can’t seem to think of it that way