Sugar
Sugar copied to clipboard
Zip: Differences to underscore; handling of matrix
Not sure if it´s intentional or not, but zip does hide some values when applied to a matrix. Underscore seems to include them.
testMatrix = [
['a', 'b', 'c'],
['a', 'b', 'c'],
['a', 'b', 'c'],
['x', 'a', 'b', 'c'],
['x', 'a', 'd1', 'b', 'c', 'd2']
]
Sugar.Array.zip.apply(this, testMatrix)
// Result:
[
["a", "a", "a", "x", "x"],
["b", "b", "b", "a", "a"],
["c", "c", "c", "b", "d1"]
]
_.zip.apply(this, testMatrix)
// Result:
[
["a", "a", "a", "x", "x"],
["b", "b", "b", "a", "a"],
["c", "c", "c", "b", "d1"],
[null, null, null, "c", "b"],
[null, null, null, null, "c"],
[null, null, null, null, "d2"]
]
Hi, sorry for the delay. Unfortunately, this is spec now... from the docs:
If the arrays passed have more elements than the original array, they will be discarded.
I agree that this is strange behavior and will look into fixing this for the next major version.