Ruby: multidimensional array to one-dimensional rows

Viewed 616

In Ruby, how do I go from this:

[
  1, 
  ["green", "blue", "black"], 
  [ ["1", "2"], ["3"], ["4", "5"] ]
]

to this?

[
  [1, "green", "1"],
  [1, "green", "2"],
  [1, "blue", "3"],
  [1, "black", "4"],
  [1, "black", "5"],
]

I tried .zip but with no luck. Any help is greatly appreciated, and of course I'm looking for a performant solution.

3 Answers
Related