[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: How to operate on 2 arrays simultaneously?

Dan Diebolt

9/10/2008 4:49:00 PM

Instead of .zip I use .transpose as it is easier to remember and makes more sense mathematically

irb(main):078:0> a=[1,2,3]
=> [1, 2, 3]

irb(main):079:0> b=%w(x y z)
=> ["x", "y", "z"]

irb(main):080:0> [a,b].transpose
=> [[1, "x"], [2, "y"], [3, "z"]]

irb(main):081:0> a.zip(b)
=> [[1, "x"], [2, "y"], [3, "z"]]