Hi,
I have two arrays:
A = [“a”, “b”, “c”, “d”, …]
B = [“1”, “2”, “3”, “4”, …]
And I need to create new array C
C = [“a$1”, “b$2”, “c$3”, “d$4”, …]
How so I do this in ruby way?
Thanks,
Hi,
I have two arrays:
A = [“a”, “b”, “c”, “d”, …]
B = [“1”, “2”, “3”, “4”, …]
And I need to create new array C
C = [“a$1”, “b$2”, “c$3”, “d$4”, …]
How so I do this in ruby way?
Thanks,
On Jan 16, 12:48 pm, kimda [email protected] wrote:
How so I do this in ruby way?
Thanks,
On Jan 16, 2008, at 3:48 PM, kimda wrote:
How so I do this in ruby way?
Thanks,
irb> A = (‘a’…‘e’).to_a; B = (1…5).to_a; C = A.zip(B).map {|(a,b)|
“#{a}$#{b}”}
=> [“a$1”, “b$2”, “c$3”, “d$4”, “e$5”]
But you shouldn’t use Capitals unless you intend to create a constant.
-Rob
Check out the ruby docs for arrays and try it itself.
Sent from my iPhone
thank you so much!!
On Jan 16, 4:24 pm, Rob B. [email protected]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs