Falsy Bouncer algorithm - any help as to why this solution isn't working? - SOLVED

Falsy Bouncer algorithm - any help as to why this solution isn't working? - SOLVED
0

#1

Hi guys,

Working on the falsy bouncer algorithm that removes false values from an array and thought I had made a solution but it doesn’t work with one combination:

solved

This solution is working for the other inputs, but for some reason null is not being removed and I am getting [1,null,2]. Any thoughts on why this is happening? I didn’t exactly use the “hints” they gave me because this jumped into my head as a possible solution immediately.

Thanks a bunch


#2

If you get rid of the if statement and add a case for null like you did for the other 5 values, then it will pass the tests.


#3

Weird! When I did that while working on the solution null wasn’t being captured in the switch statement. Now it’s working. There were also some resources that stated null didn’t work in switch statements so I tried the if. Anyways, thanks a bunch!


#4

I don’t see your code. I’m curious to see what you did.
Here’s mine:

Summary
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var check = (x) => Boolean(x);
  return arr.filter(check);
}

bouncer([7, "ate", "", false, 9]);

side note: the arrow function was done afterwards just for kicks. I don’t think the FCC challenges console accepts them.


#5

My solution also used the arrow function syntax. Click below to see my solution.

function bouncer(arr) {
  return arr.filter( (val)=> val);
}

#6

Wow, that’s amazingly simple!