Ensure _.reduce doesn't assign accumulator a collection value if its length is 0.

This commit is contained in:
John-David Dalton
2013-12-25 00:21:45 -06:00
parent 2dab4ccf85
commit 0438fa6816
5 changed files with 41 additions and 27 deletions

View File

@@ -6367,6 +6367,20 @@
var actual = func([], noop, undefined);
strictEqual(actual, undefined);
});
test('`_.' + methodName + '` should return `undefined` for empty collections when no `accumulator` is provided (test in IE > 9 and modern browsers)', 2, function() {
var array = [],
object = { '0': 1, 'length': 0 };
if ('__proto__' in array) {
array.__proto__ = object;
strictEqual(_.reduce(array, noop), undefined);
}
else {
skipTest();
}
strictEqual(_.reduce(object, noop), undefined);
});
});
/*--------------------------------------------------------------------------*/