SG17 SG17 - 8 months ago 45
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?


String#count might help you:

def favorite_wish
  max_key = @submitted_wishes.keys.max_by { |wish| wish.count('aeiou') }