Skip to content

Instantly share code, notes, and snippets.

@bflannery
Created December 23, 2016 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bflannery/96fe2c2b891e415eb15517fdef9c3c1d to your computer and use it in GitHub Desktop.
Save bflannery/96fe2c2b891e415eb15517fdef9c3c1d to your computer and use it in GitHub Desktop.
Remove all falsy values from an array
// Remove all falsy values from an array.
function bouncer(arr) {
return arr.filter(Boolean);
}
console.log(bouncer([7, "ate", "", false, 9]));
console.log(bouncer([1, null, NaN, 2, undefined]));
console.log(bouncer(["a", "b", "c"]));
console.log(bouncer([false, null, 0, NaN, undefined, ""]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment