Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created March 19, 2017 01:09
Show Gist options
  • Select an option

  • Save lachlan-eagling/bcf3af3f6602609fe281bccbb32c70bd to your computer and use it in GitHub Desktop.

Select an option

Save lachlan-eagling/bcf3af3f6602609fe281bccbb32c70bd to your computer and use it in GitHub Desktop.
// Remove all "flasy" values from an Array.
// Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
function bouncer(arr) {
var test = function(x){
return Boolean(x);
};
for(var i = 0; i < arr.length; i++){
var temp = Boolean(arr[i]);
arr = arr.filter(test);
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment