Created
March 19, 2017 01:09
-
-
Save lachlan-eagling/bcf3af3f6602609fe281bccbb32c70bd to your computer and use it in GitHub Desktop.
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
| // 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