raym0nd
raym0nd

Reputation: 3262

Ruby Array changing substring

I would like to display the following:

anu1 cau1 doh1 bef1

To do that I need to complete the following Ruby code by adding only ONE statement.

 a = ["ant", "cat", "dog", "bee"]

Upvotes: 2

Views: 109

Answers (2)

Rion Williams
Rion Williams

Reputation: 76577

It sounds like you need to perform a succ function each of the words, which will give you the next value for each of them, then you would just need to append "1" to each.

Example: -Forgive my syntax, Haven't used Ruby in a while-

a.map {|word| word.succ << "1"}

should output:

["anu1", "cau1", "doh1", "bef1"]

Upvotes: 3

Guilherme Bernal
Guilherme Bernal

Reputation: 8313

a = ["ant", "cat", "dog", "bee"]
# => ["ant", "cat", "dog", "bee"]

a.map {|str| str.succ << "1" }
# => ["anu1", "cau1", "doh1", "bef1"]

Upvotes: 1

Related Questions