size enhancement as ternary and _.size(arr) test case

This commit is contained in:
Raymond May Jr
2012-03-20 09:31:50 -05:00
parent 5827e4a40a
commit 4c2a85f9c5
2 changed files with 2 additions and 5 deletions

View File

@@ -275,6 +275,7 @@ $(document).ready(function() {
test('collections: size', function() {
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
equal(_.size([1, 2, 3]), 3, 'can compute the size of an array');
});
});

View File

@@ -309,11 +309,7 @@
// Return the number of elements in an object.
_.size = function(obj) {
if (_.isArray(obj)) {
return obj.length;
}else{
return _.keys(obj).length;
}
return _.isArray(obj) ? obj.length : _.keys(obj).length;
};
// Array Functions