Skip to content

Commit 9ac45c6

Browse files
committed
Merge pull request #2079 from smelnikov/isArrayLike-fix
fixed isArrayLike returning true for 0
2 parents 19db749 + 7770a21 commit 9ac45c6

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

test/collections.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@
789789
equal(_.size(new String('hello')), 5, 'can compute the size of string object');
790790

791791
equal(_.size(null), 0, 'handles nulls');
792+
equal(_.size(0), 0, 'handles numbers');
792793
});
793794

794795
test('partition', function() {

underscore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
// Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
128128
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
129129
var isArrayLike = function(collection) {
130-
var length = collection && collection.length;
130+
var length = collection != null && collection.length;
131131
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
132132
};
133133

0 commit comments

Comments
 (0)