AniUI Academy
medium+250 XPPractice

Zip any number of arrays together

Charting libraries hand you parallel arrays: one of labels, one of values, one of colours. To render a legend you need them as rows, one per data point.

Implement zip(...arrays) taking any number of arrays as separate arguments. Return an array of rows, where row i contains the element at index i from each input array, in the order the arrays were passed. The result has as many rows as the longest input array. Where a shorter array has no element at that index, use null. Calling zip() with no arguments returns an empty array, and so does zipping only empty arrays.

What it has to do

  • Accept a variable number of array arguments.
  • Produce one row per index of the longest input array.
  • Fill gaps from shorter arrays with null.
  • Keep values in the same order the arrays were passed.
  • Return [] when called with no arguments or with only empty arrays.

Your workspace

Try it yourself
Loading playground...

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.