Created
February 4, 2026 15:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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