Skip to content

Falsy Bouncer Bug #7587

Closed
Kennard123661 opened this Issue · 4 comments

4 participants

@Kennard123661

FreeCodeCamp Issue template

To Use this Template:

  • Fill out what you can
  • Delete what you do not fill out

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

  • Google Chrome, Version 49.0.2623.87 m
  • Windows 10 64 bit

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, ""]);

If relevant, paste all of your challenge code in here

Screenshot

@AkiraLaine
Free Code Camp member

Hey @Kennard123661, if you need help, please go to our main room or our HelpJavascript room. GitHub is for issues only :smile:

@AkiraLaine AkiraLaine closed this
@Kennard123661
@alistermada

@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].

@kreddibletrout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.