B
B
Bogdan2017-06-26 21:10:53
Ruby on Rails
Bogdan, 2017-06-26 21:10:53

Rails array union?

Hello, do not tell me how best to combine several arrays. Here's how the example

f = [ 'f1', 'f2', 'f3' ]
 a = [ 'a1', 'a2', 'a3' ]
result =  a.map{ | v | f.map{ |v2| [v, v2] } }
#=> [, , ]

and you need the result to be a two-dimensional array

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitri Sinitsa, 2017-06-27
@bogdan_uman

a.product(f)

E
Egor Kazantsev, 2017-06-26
@saintbyte

Have you tried the zip method?

B
Bogdan, 2017-06-26
@bogdan_uman

I made it with such a crutch, but maybe there is a better option?

d = []
a.each{ | v | f.each{ |v2| d<<[v, v2] } }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question