Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2015 06:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Remove all falsy values from an array. Falsy values in javascript are false, null, 0, "", undefined, and NaN.
// Bonfire: Falsy Bouncer
// Author: @joepichardo
// Challenge:
// Learn to Code at Free Code Camp (
function bouncer(arr) {
// Don't show a false ID to this bouncer.
function noFalsyVals(value){
//function used in conjunction with filter() function
//compares falsy values and returns value if none are found
//else it returns nothing
if (value !== false || value !== null || value !== undefined || value.isNaN() === false){
return value;
arr = arr.filter(noFalsyVals);
return arr;
bouncer([7, "ate", "", false, 9]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment