Can someone tell me why I am failing the last testcase whenever I have this bit of code in?
isNaN(collection[i][pre]) == true
Testcase that fails WITHOUT this code:
truthCheck([{"single": "double"}, {"single": NaN}], "single")
All code:
function truthCheck(collection, pre) {
let flag = true;
//Check if pre exists as a property in any of the objects that are in collection
for(var i = 0; i<collection.length; i++){
if(collection[i].hasOwnProperty(pre)){
if(collection[i][pre] == false || collection[i][pre] == 0 || collection[i][pre] == null || collection[i][pre] == undefined || isNaN(collection[i][pre]) == true){
flag = false;
}
}else{
flag = false;
}
}
return flag;
Testcases that fail WITH the NaN code in:
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")
and
truthCheck([{"single": "yes"}], "single")
I’m sure there is some pattern to why these fail when I add the NaN code in versus when I take it out, but I can’t figure it out.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true