question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Falsy Bouncer kluge coding

See original GitHub issue

Challenge Falsy Bouncer has an issue. User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:48.0) Gecko/20100101 Firefox/48.0. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


function bouncer(arr) {
  // Don't show a false ID to this bouncer.
 function notFalse (item) {
   var x = typeof(item);
//   console.log(" item " + item + " x-typeof " + x);
//   if (x === "number")
//     if (!item)
//       item =0;  // force NaN to be 0
   
   
   if (item === false) {
     return false;
   } else if (item === "") {
     return false;
   } else if (item === null) {
     return false;
   } else if (item === 0) {
     return false;
   } else if (item === undefined) {
     return false;
   } else if (x === "number" && isNaN(item)) {  // "a" would fail this test without === number
     return false;
   } else {
     return true;
   }   
 }
      
      
var newArr = arr.filter(notFalse);      
    
  
  return newArr;
}

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


My comments: This was a challenging exercise. I have read the other comments in this forum and understand that this is a borderline bug/quirk of JS coding that is unlikely to change. The “falsy” concept is not monolithic when it comes to testing for all the possible falsy values. NaN is the exception and should only be applied when the typeof (item) === “number” whereas the other falsy concepts can be tested regardless of object type.
I wonder if the typeof () function should be added to the the helpful links on this challenge?
I also wonder if it would not be better to test for the falsy concepts AFTER determining the object type, for all falsy results? Main issue here is that the function isNaN(x) will return true for any string/character values tested (probably boolean as well but my code tests for the boolean falsy prior to the NaN test).

I know I should likely be using the chat/help function for this and while new at freecodecamp I expect to be up and running on github shortly.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
systimoticcommented, Jan 25, 2017

@codeman869 I like it! I think “first” could be omitted, but I like the balance between pointing the camper in the right direction, but not telling them specifically which tool they should use. Do you want to create a PR for this?

1reaction
systimoticcommented, Jan 21, 2017

@codeman869 Good points!

I actually used your method as well when initially playing around with possible solutions, before taking a look at the link.

I do agree that maybe this is pointing to a specific solution too much. If we add your link, we’re pointing to two solutions, which could be very confusing. As a camper, I would think that I would have to do something with both links.

The page on logical operators also doesn’t really show how to convert a value to a boolean. It does state

!!bCondition is always equal to bCondition,

but I wouldn’t be able to tell that it was converted to a boolean if I didn’t know already.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Falsy Bouncer - Basic Algorithm Scripting - Free Code Camp
In this basic algorithm scripting tutorial we do the falsy bouncer project. This is another tutorial that makes up a series where I...
Read more >
Solving "Falsy Bouncer" / freeCodeCamp Algorithm Challenges
Our Approach. Read everything first. Read the instructions clearly, read the starter code we're given, and read the tests and understand ...
Read more >
freeCodeCamp Challenge Guide: Falsy Bouncer
Code Explanation. We create a new empty array ( filteredArr ). We use a for cycle to iterate over all elements of the...
Read more >
Untitled
Stache fort lauderdale dress code, Last minute stays sydney, ... Bouncers salary uk? ... Stamina growth tips, Emil gemzell, Kluge tiere in fabeln, ......
Read more >
Untitled
4 seasons nursery nj, Yakima washington zip code map! ... Koolhydraatarm ontbijt, Samil korea transformer, False profit band, Belgium based imaging company ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found