Correct the resolution of length in _.zip.

This commit is contained in:
John-David Dalton
2014-06-15 09:41:27 -07:00
parent 4ccb3810c2
commit 39bdd37615
3 changed files with 18 additions and 3 deletions

View File

@@ -2026,8 +2026,8 @@
*/
function zip() {
var index = -1,
length = max(pluck(arguments, 'length')),
result = Array(length < 0 ? 0 : length);
length = isArray(length = max(arguments, 'length')) && length.length || 0,
result = Array(length);
while (++index < length) {
result[index] = pluck(arguments, index);

View File

@@ -3833,7 +3833,7 @@
function zip() {
var array = arguments.length > 1 ? arguments : arguments[0],
index = -1,
length = (array && array.length) ? max(array, 'length').length : 0,
length = isArray(length = max(array, 'length')) && length.length || 0,
result = Array(length);
while (++index < length) {

View File

@@ -10434,6 +10434,21 @@
deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
});
test('should treat falsey values as empty arrays', 1, function() {
var expected = _.map(falsey, _.constant([]));
var actual = _.map(falsey, function(value) {
return _.zip(value, value, value);
});
deepEqual(actual, expected);
});
test('should support consuming its return value', 1, function() {
var expected = [['barney', 'fred'], [36, 40]];
deepEqual(_.zip(_.zip(_.zip(_.zip(expected)))), expected);
});
test('should support consuming its return value', 1, function() {
var expected = [['barney', 'fred'], [36, 40]];
deepEqual(_.zip(_.zip(_.zip(_.zip(expected)))), expected);