Crom305 Crom305 - 22 days ago 15
Ruby Question

Creating a method in Ruby that takes in an array and returns a string

How would you solve this problem in Ruby. "Define a method called yeller that takes in an array of characters and returns a string with an ALLCAPS version of the input. Verify that yeller([’o’, ’l’, ’d’]) returns "OLD". Combine the .join, .map, .upcase methods."

So far I have:

def yeller(x)
x.map do |y|
y.upcase.join
puts y
end
end
yeller(['o', 'l', 'd'])

Answer

try this

def yeller(x)
  x.map! do |y|
    y.upcase
  end
  puts x.join
end
yeller(['o', 'l', 'd'])
Comments