Skip to content

Instantly share code, notes, and snippets.

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