Unzip rows back into columns
A table comes back from the server as rows. Your chart wants columns: all the x values in one array, all the y values in another. That is a transpose.
Implement unzip(rows) where rows is an array of arrays. Return an array of columns: column j contains the element at index j from each row, in row order. The result has as many columns as the longest row. Where a shorter row has no element at that index, use null. An empty rows array returns an empty array. Applying unzip twice to a rectangular input gives back the original structure.
What it has to do
- Produce one column per index of the longest row.
- Keep values in row order within each column.
- Fill gaps from shorter rows with
null. - Return
[]for an empty input. - Round-trip correctly: unzipping a rectangular result twice returns the original.
Your workspace
Ready to check it?
5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
AI Crack & Solution Assist
Stuck? Get instant AI hints or break down the optimal solution.
Stuck? The javascript course covers everything this challenge needs.