Last active
May 9, 2018 05:22
-
-
Save earlonrails/21d4729b85dbdb6c13b724b5d58fcd8e to your computer and use it in GitHub Desktop.
The Popular goat latin interview question
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
#!/usr/bin/env ruby | |
sentence = ['This','is','goat','latin'] | |
vowel = ['a', 'e', 'i', 'o', 'u'] | |
result = [] | |
sentence.each_with_index do |word, idx| | |
aaa = "ma" + "a" * (idx + 1) | |
if vowel.include?(word[0]) | |
result << word + aaa | |
else | |
result << word[1..-1] + word[0] + aaa | |
end | |
end | |
puts result.join(' ') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment