added an isEmpty function that works on arrays and objects

This commit is contained in:
Jeremy Ashkenas
2009-11-07 23:04:18 -05:00
parent d4f6e1a42f
commit b5920e94a3
4 changed files with 32 additions and 5 deletions

View File

@@ -146,9 +146,7 @@
if (_.isArray(obj)) return _.indexOf(obj, target) != -1;
var found = false;
_.each(obj, function(value) {
if (found = value === target) {
throw '__break__';
}
if (found = value === target) throw '__break__';
});
return found;
};
@@ -409,6 +407,11 @@
return true;
};
// Is a given array or object empty?
_.isEmpty = function(obj) {
return (_.isArray(obj) ? obj : _.values(obj)).length == 0;
};
// Is a given value a DOM element?
_.isElement = function(obj) {
return !!(obj && obj.nodeType == 1);