Skip to content

Instantly share code, notes, and snippets.

@AdrianSkar
Last active May 29, 2018 09:24
Show Gist options
  • Save AdrianSkar/d614b074dfcd192ec8f3f66bb1febbad to your computer and use it in GitHub Desktop.
Save AdrianSkar/d614b074dfcd192ec8f3f66bb1febbad to your computer and use it in GitHub Desktop.
[JS] fCC's exercise Falsy bouncer: https://codepen.io/adrianskar/pen/MGRXKy
// Falsy bouncer
function bouncer(arr) {
return arr.filter(function(val) {
return Boolean(val) !== false; // Same as: return (val);
});
}
bouncer([7, "ate", "", false, null, 9, NaN]);
/* This does the trick too:
var newArr =[];
for (var i = arr.length - 1; i >= 0; i--) {
switch(true){
case !!arr[i]:
newArr.push(arr[i]);
break;
default:
break;
}
}
return newArr.reverse();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment