I am trying to take a sentence, and reverse the positions of the letters in each word.
Below is my code that does not work:
def test(sentence)
array = []
array << sentence.split
array.collect {|word| word.reverse}
end
My problem is with:
array << sentence.split
It says it divides each word, but when I use interpolation, it reverses the whole sentence. Below is a similar code that works:
def test2
dog = ["Scout", "kipper"]
dog.collect {|name| name.reverse}
end
But it does not accept a sentence, and it already has the array defined.