Created
September 12, 2018 07:42
-
-
Save vibhasbhingarde/e04f6dee60fc51fb21ea7e19ee94613c to your computer and use it in GitHub Desktop.
Reject undefined/Null element from array in short getting rid of conditional push
This file contains 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
//https://triin.net/2010/01/13/Fighting_the_uglyness_of_Array.push() | |
var buttons = [ | |
new OpenButton(), | |
isPayingCustomer() ? new ExportButton() : null, | |
new SaveButton(), | |
new DeleteButton() | |
].compact(); | |
Array.prototype.compact = function() { | |
return this.filter(function(x) { | |
return x !== null && x !== undefined; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment