Skip to content

Instantly share code, notes, and snippets.

@abloom
Created March 19, 2013 16:42
Show Gist options
  • Save abloom/5197737 to your computer and use it in GitHub Desktop.
Save abloom/5197737 to your computer and use it in GitHub Desktop.
names = %w(
Andrew\ Bloom
Christopher\ Castro
Diego\ Lopez
Steven\ Targos
Matt\ Milkowski
Christine\ Livingood
Marta\ Contino
)
# count all vowels
results = names.inject({}) do |hsh, name|
hsh[name] = name.scan(/[aeiouy]|[AEIOUY]/).length
hsh
end
# extract the winner(s) -- most vowels
max = results.values.max
winners = results.inject([]) do |arr, (key, value)|
arr << key if value == max
arr
end
puts results.inspect
puts
puts winners.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment