2

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"]
1
  • @muistooshort Im learning Ruby, it's an online exercise. Commented Dec 7, 2011 at 21:26

2 Answers 2

3

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"]
Sign up to request clarification or add additional context in comments.

1 Comment

a.collect {|x| print x.next+"1 "} This is what I did.
1
a = ["ant", "cat", "dog", "bee"]
# => ["ant", "cat", "dog", "bee"]

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.