SG17 SG17 - 1 year ago 81
Ruby Question

Writting a method to check the number of vowels in a string

I have a hash of data that is holding different strings as its Key. I need to create a new method in my class that will count the number of vowels in each key and then return the key with the most vowels. I am very stuck and this is what I have so far.

def favorite_wish
vowels = ["a", "e", "i", "o", "u"]
@submitted_wishes.each_key do |wish|
wish.split(' ')
wish.each do |check|
if check == vowels

Can anyone help?

Answer Source

String#count might help you:

def favorite_wish
  max_key = @submitted_wishes.keys.max_by { |wish| wish.count('aeiou') }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download