mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Merge pull request #515 from octatone/master
Proposed solution for _.size speed improvement RE issue #496
This commit is contained in:
@@ -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');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -309,7 +309,7 @@
|
||||
|
||||
// Return the number of elements in an object.
|
||||
_.size = function(obj) {
|
||||
return _.toArray(obj).length;
|
||||
return _.isArray(obj) ? obj.length : _.keys(obj).length;
|
||||
};
|
||||
|
||||
// Array Functions
|
||||
|
||||
Reference in New Issue
Block a user