Falsy bouncer code doesn't work

Falsy bouncer code doesn't work
0

#1

Not sure why this doesn’t work and unsure where to go from here.

function bouncer(arr) {
//Don't show a false ID to this bouncer.// 
  function getItOut(value) {
for (var i = 0; i < arr.length ; i++) {
if ( arr[i] === false ) {
 return value;
}
} return arr.filter(getItOut);
} 
}                        
bouncer(["a", "b", "c"]);

#2

@okdatapad what is the result of passing ["a", "b", "c"], to bouncer()?


#3

I edited your post a bit. You used the code formatting backticks, which is great, but they need to be on their own lines for the formatting to work. I also added spoiler tags because we’re looking at one of the challenges.


#4

nothing, i just get a blank box


#5

You are using strict equality which checks the value as well as the type.

The elements in the array are strings and false is a boolean so the comparison will always be false.


#6

I changed it to

 arr[i] !== true

and it still doesn’t work.


#7

You’re using “arr” instead of the local variable “value” and you’ll probably want to change it from arr[i] === false to arr[i] !== false, or falseValues.indexOf(arr[i]) === -1 where falseValues is an array of false values.

How do you get your code to color and format like that?


#8

You’re also misusing filter. Filter iterates over the entire array, there’s no need to use a for loop.

You should just do it as a callback


#9

I got rid of the for loop and it worked, I have no idea why though lol


#10

Yeah that’s weird. return arr.filter(function(x){ return x }); works.


#11