I have a matrix that can vary in width depending on the results received from the server. Here is an example:
[undefined, undefined]
[1, 2, 3, 4]
[1, 2]
[undefined, undefined, undefined]
[1, 2, 3, 4, 5, 6]
My goal is to transform it into this format:
[undefined, 1, 1, undefined, 1]
[undefined, 2, 2, undefined, 2]
[undefined, 3, undefined, undefined, 3]
[undefined, 4, undefined, undefined, 4]
[undefined, undefined, undefined, undefined, 5]
[undefined, undefined, undefined, undefined, 6]
The height of the matrix should match the maximum width of the initial example. I tried using the code snippet I found online:
array.map((row, i) => array.map(col => col[i]))
However, this solution does not change the height of my matrix. I attempted to use two for loops but did not achieve the desired outcome. Any assistance would be greatly appreciated!