-
-
Save jcsalterego/5234470 to your computer and use it in GitHub Desktop.
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
def translate(phrase) | |
phrase.split.inject([]) do |final_pigs, word| | |
char = word.split(//) | |
if char[0].match(/[aeiou]/) | |
final_pigs << "#{word}ay" | |
else | |
new_string = char | |
until new_string[0].match(/[aeio]/) | |
new_string << new_string.shift | |
end | |
final_pigs << new_string.join + "ay" | |
end | |
final_pigs | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks @jcsalterego Really interesting use of inject! I really hadn't considered doing the summation of [ ] and word.