andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.53k stars 306 forks source link

Zip: Differences to underscore; handling of matrix #615

Open thomasf1 opened 7 years ago

thomasf1 commented 7 years ago

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"]
]
andrewplummer commented 6 years ago

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.