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?
1 Like