Falsy bouncer: My solution please help

Falsy bouncer: My solution please help
0

#1

Hi. I am have attempted the falsy Bouncer, but I have a hard time dealing with the falsy NaN. I have tried to use isNaN and other options but still nothing. Please can someone help me with this very beginner solution.

Can it be fixed?

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  
 var falsyValues = [false, null, 0, "", undefined, NaN];
  var array =[];
  array = arr.filter(function (value){
//     for (var i = 0; i < falsyValues.length; i++){
    if(value === false && value !== "" && value !== null && value !== 0 && value !== undefined ){
      return  arr; 
    }
    
//     }
             
             });
  
  return array;
}

#2

isNaN doesn’t work as you would expect. It allows coercion, so if you passed it, say, 'hello', it will coerce it to a number and come up with NaN, so it returns true.

There’s a stricter Number.isNaN function that only works with numbers and returns true just for actual NaN values.


#4

Thanks. You helped me to understand the filter() function better;

my solution:

function bouncer(arr) {
// Don’t show a false ID to this bouncer.

var array =[];
array = arr.filter(function (value){
return value;

         });

return array;
}


#5
**********Falsy Bouncer Solution********

function bouncer(arr) {

function falsyValues(val){
return val;
}
return arr.filter(falsyValues);
}


#6

hello i am having trouble understanding how your code is working. could you please explain what is happening.


#7

Which code are you talking about?


#8

sorry for not clarifying. I was talking about ahsanwaseem’s code, but after studying it for a while it all connected. thank you for replying though!