Sugar icon indicating copy to clipboard operation
Sugar copied to clipboard

Zip: Differences to underscore; handling of matrix

Open thomasf1 opened this issue 8 years ago • 1 comments

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"]
]

thomasf1 avatar Sep 06 '17 21:09 thomasf1

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.

andrewplummer avatar Jul 29 '18 04:07 andrewplummer