Skip to content

Instantly share code, notes, and snippets.

@SerhiiLihus
Created December 4, 2015 13:15
Show Gist options
  • Save SerhiiLihus/22a8706a11ab286ffd24 to your computer and use it in GitHub Desktop.
Save SerhiiLihus/22a8706a11ab286ffd24 to your computer and use it in GitHub Desktop.
Remove all falsy values from an array
// Bonfire: Falsy Bouncer
// Author: @serhiilihus
// Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer?solution=function%20bouncer(arr)%20%7B%0A%20%20%20return%20arr.filter(function%20(value)%20%7B%0A%20%20%20%20if%20(new%20Boolean(value).valueOf()%20%3D%3D%3D%20true)%20return%20value%3B%0A%20%20%7D)%3B%0A%7D%0A%0Abouncer(%5B7%2C%20%22ate%22%2C%20%22%22%2C%20false%2C%209%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function bouncer(arr) {
return arr.filter(function (value) {
if (new Boolean(value).valueOf() === true) return value;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment