Why can't get six true from the code?

Why can't get six true from the code?
0

#1
function bouncer(arr) {
  rule=[false,null,0,"",undefined,NaN];
  changed=[];
  for (i=0;i<arr.length;i++){
    dis=false;
    for(j=0;j<6;j++){
      if(arr[i]===rule[j]){dis=true;}
      break;
    }
    console.log(dis);
  }
}

bouncer([false, null, 0, NaN, undefined, “”]);
VM86:10 true
5VM86:10 false

Why can’t get six ture from my code?


#2

you always break first time through the loop. You need to put the break inside the if I think. Also, just set dis once before the loop. try this:

dis = false;
for( i=0; i<arr.length; i++){
  if( arr[i] === rule[j]) {
    dis = true;
    break;
  }
}

#3

problem still remains here.


#4

I think it is working. you get 5 out 6 true. NaN === NaN in console gives false.

From MDN docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN you can see NaN === NaN return false


#5

Then how to make then output six true ?


#6

I’m not sure what you’re trying to do. Is it one of the challenges? Can you link a codepen I can look at?