【发布时间】:2016-09-27 04:05:05
【问题描述】:
我目前有一个输入 [['a', [0, 1]], ['b', [1]]]。我正在尝试将第一项与[0,1] 中的每个元素组合在一起,即:'a' 中的['a',[0,1] => [['a',0],['a',1],['b',1]] 就像有序对一样。我已经做到了,但它似乎过于复杂我认为可能有一种我忽略的方法。
[[0, [0, 1]], [1, [1]]].map.with_index{|x,y| x[1].map{|ele| [y,ele]}}.flatten(1)
#I used 'a'&'b' in the example to help with any confusion.
【问题讨论】:
标签: arrays ruby combinations