Skip to content

Instantly share code, notes, and snippets.

@marcalj
Created July 7, 2011 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcalj/1069747 to your computer and use it in GitHub Desktop.
Save marcalj/1069747 to your computer and use it in GitHub Desktop.
compactObject Underscore function
/**
* 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;
}
});
@evilive3000
Copy link

!!!value is not equal to !value ? what's the point?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment