Falsy Bouncer help

Falsy Bouncer help

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var x = [false,null,0,"",undefined,NaN];
  arr = arr.filter(function(x){
    return x;
  return arr;

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

I wrote the above code. It works but I don’t know why. Can somebody explain me?


I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


You say that you wrote it, so how did you expect it to work? What led you to that solution?


Since you wrote, you should be able to describe to us what your thought process was (your algorithm) for why it works. Take a shot at explaining it to us and we can correct any misunderstandings you may have.