Two arrays problem (although different from the other two ar

I have a bunch of japanese encoded words in Kanji and Hirigana (I
think). Each set is broken into two pieces, name and type, which can be
combined to produce many more words, so this looks like a classic
‘iterate over two arrays problem’

This is what I have, I tried messing with inject and I couldn’t get the
desired output. If anyone wants to golf it I’d like to learn what I
should be doing instead

corp_data_1.each do |cd1|
corp_data_2.each do |cd2|
rd << cd1 + cd2
end
end

Thanks
Kev

Kev J. wrote:

  corp_data_2.each do |cd2|
    rd << cd1 + cd2
  end
end

Thanks
Kev

Not necessarily better but:

rd = corp_data_1.map{|cd1| corp_data_2.map{|cd2| cd1 + cd2}}

cheers

I’m not really clear what you’re trying to do. Could you provide a bit
more detail? Do the elements of corp_data1 and corp_data2 correspond to
one another or are they independent? Are you trying to get output with
the same number of elements, or with a number of elements equal to the
product of the two (a sort of cartesian product)?

If it’s the former, you should be able to do it with zip and map, if
it’s the latter, it seems like what you have should be appropriate.