I'm having an array arr
of maps, for example
arr == [ { pos => [0,0], color => :red, ... },
{ pos => [0,1], color => :green, ...},
{ pos => [1,0], color => :fuchsia, ...},
{ pos => [1,1], color => :red, ...},
...
]
Where
arr.map { |item| item.pos }
forms a cartesian product of integer ranges [0..n] x [0..m]
I'd gladly access elements by their first coordinate! So use something like
`newArr` == [
[{ second_coord => 0, color => :red...}, { second_coord => 1, color => :green,...}, .. ],
[{ second_coord => 0, color => :fuchsia,...}, { second_coord => 1, color => :red, ...},..],
...
]
Because if I could access it like it, I believe I could redact my code pretty elegantly and readable. If the transformation is short and readable, or at least short. Any hints?