Created
December 6, 2016 18:04
-
-
Save jdenen/820103748b69fe664bd1f1cd58794bb9 to your computer and use it in GitHub Desktop.
This file contains 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
VOWELS = ['a', 'e', 'i', 'o', 'u'] | |
word = gets.chomp.chars.map(&:downcase) | |
def modify_vowel(char) | |
VOWELS.include?(@previous_char) ? char : "idig#{char}" | |
end | |
def is_vowel?(char) | |
VOWELS.include?(char) | |
end | |
def replace_eligible_vowel(char) | |
is_vowel?(char) ? modify_vowel(char) : char | |
end | |
gibberish = word.each_with_object([]).with_index do |(char, new_word), index| | |
@previous_char = word[index - 1] unless index.zero? | |
new_word << replace_eligible_vowel(char) | |
end | |
puts gibberish.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment