Falsy Bouncer Bug #7587
Kennard123661
commented
Hey @Kennard123661, if you need help, please go to our main room or our HelpJavascript room. GitHub is for issues only
AkiraLaine
closed this
Hi Akira!
The issue is that my switch code should remove the null for the array and make an empty array. However, it removes everything but the null. I've tried it with my other if codes but it still didn't work, much to my dismay.
With Regards,
Kennard Ng
On 17 Mar 2016, at 6:31 PM, Akira Laine <notifications@github.com<mailto:notifications@github.com>> wrote:
Closed #7587<#7587>.
-
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub<#7587 (comment)>
alistermada
commented
@Kennard123661 Actually, the return value for bouncer([false, null, 0, NaN, undefined, ""])
using your code would be [NaN]
. You can confirm this by adding console.log(arrayNew)
just before it is returned and checking your browser's console.
Your switch
statement doesn't catch NaN
because NaN
compares unequal to all values including itself. More info about NaN
.
I'm not sure why it outputs [null]
in the challenge console on the left when it actually is [NaN]
.
You sent this to the wrong member. I'm still learning what 'img' means.
(We'll talk in a few years when my training wheels are off)
…
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FreeCodeCamp Issue template
To Use this Template:
NOTE: ISSUES ARE NOT FOR CODE HELP - Ask for Help at https://gitter.im/FreeCodeCamp/Help
Issue Description
null appears to not be removed from the array when .filter() method is applied.
Browser Information
Your Code
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var arrayNew = [];
arrayNew = arr.filter(function(val) {
switch(val) {
case null:
case false:
case 0:
case "":
case undefined:
case NaN:
return false;
default:
return true;
}
});
return arrayNew;
}
bouncer([7, "ate", "", false, 9]);
bouncer([false, null, 0, NaN, undefined, ""]);
Screenshot