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

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:


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

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.

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!

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

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.

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

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

Wow, that’s amazingly simple!