Created
July 7, 2011 15:19
-
-
Save marcalj/1069747 to your computer and use it in GitHub Desktop.
compactObject Underscore function
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
/** | |
* compactObject | |
* ============= | |
* Simple port of Underscore Array's compact function. You need to replace _.trim function if underscore.string it's not included. | |
*/ | |
_.mixin({ | |
compactObject: function(to_clean) { | |
_.map(to_clean, function(value, key, to_clean) { | |
if ( !!!value || (_.isString(value) && _.trim(value).length === 0)) { | |
delete to_clean[key]; | |
} | |
}); | |
return to_clean; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
!!!value is not equal to !value ? what's the point?