mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
size enhancement as ternary and _.size(arr) test case
This commit is contained in:
@@ -275,6 +275,7 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
test('collections: size', function() {
|
test('collections: size', function() {
|
||||||
equal(_.size({one : 1, two : 2, three : 3}), 3, 'can compute the size of an object');
|
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -309,11 +309,7 @@
|
|||||||
|
|
||||||
// Return the number of elements in an object.
|
// Return the number of elements in an object.
|
||||||
_.size = function(obj) {
|
_.size = function(obj) {
|
||||||
if (_.isArray(obj)) {
|
return _.isArray(obj) ? obj.length : _.keys(obj).length;
|
||||||
return obj.length;
|
|
||||||
}else{
|
|
||||||
return _.keys(obj).length;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Array Functions
|
// Array Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user