My goal is transpose a matrix; however, the sub-arrays do not all have equal length. For example: [[1,2,3], [4,5], [0,-1,0,0]]. I can't transpose this because the indices don't match up. What I need is:
[[1,2,3,undefined],
[4,5,undefined,undefined],
[0,-1,0,0]]
So that the shorter rows all match the same length as the longest row, but then are filled with undefined in the extended slots.
I'm well aware I can do this in ways that are probably considered slower or more crude, namely by initializing and empty array and copying, or concating arrays of undefined. Does javascript have some sort of native way of doing this? I took a look at fill, but it doesn't seem like what I need.
undefinedis the right thing to add.