Sorry for the poor title, I just don't know how to express what I want here without examples.
I have the following
[
[ [1,2], true ],
[ [3,4], false ]
]
and I want to get
[
[1, true],
[2, true],
[3, false],
[4, false]
]
Is there any clean way to do this in ruby?
arr.flat_map { |(x,y), bool| [[x,bool], [y,bool]] }. Notice that all the answers reproduce the array in your example. Had you assigned a variable to it (arr = [[[1, 2], true], [[3, 4], false]]) that would not have been necessary. For that reason it is advised to assign a variable to all inputs in examples given in questions.