How to list several transfers in ruby?

I know that two arrays can be archived, and the result can be repeated using #each. But how do you do this with an unknown number of enumerators? Let them talk

anand = %w(1-0 0.5-0.5 0.5-0.5 1.0) carlsen = %w(0-1 0.5-0.5 0.5-0.5 1.0) kramnik = %w(0.5-0.5 0.5-0.5 0.5-0.5 1.0) players= [anand, carlsen, kramnik] #something smart players.each{|round|puts round} #first line should be "1-0 0-1 0.5-0.5" 
+4
source share
2 answers
 players.transpose.map {|a| a.join(" ")} 
+9
source
 anand.zip(carlsen, kramnik) do |round| puts round.join(" ") end 

This will print:

 1-0 0-1 0.5-0.5 0.5-0.5 0.5-0.5 0.5-0.5 0.5-0.5 0.5-0.5 0.5-0.5 1.0 1.0 1.0 
+4
source

Source: https://habr.com/ru/post/1306585/


All Articles