Skip to content

Instantly share code, notes, and snippets.

@enderahmetyurt
Created February 4, 2026 15:05
Show Gist options
  • Select an option

  • Save enderahmetyurt/cffeafafe142c7c36156acf521331cdf to your computer and use it in GitHub Desktop.

Select an option

Save enderahmetyurt/cffeafafe142c7c36156acf521331cdf to your computer and use it in GitHub Desktop.
You are given a string consisting of lowercase words, each separated by a single space. Determine how many vowels appear in the first word. Then, reverse each following word that has the same vowel count.
# Examples:
# `flippedy("cat and mice")
# > "cat dna mice"
#
def flippedy(input)
words = input.split(" ")
vowels_count = words.first.scan(/[aeiou]/).count
words.each_with_index.map { |w, i|
if i > 0 && w.scan(/[aeiou]/).count == vowels_count
w.reverse
else
w
end
}.join(" ")
end
p flippedy("cat and mice")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment