Last active
May 29, 2018 09:24
-
-
Save AdrianSkar/d614b074dfcd192ec8f3f66bb1febbad to your computer and use it in GitHub Desktop.
[JS] fCC's exercise Falsy bouncer: https://codepen.io/adrianskar/pen/MGRXKy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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