Skip to content

Instantly share code, notes, and snippets.

@earlonrails
Last active May 9, 2018 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earlonrails/21d4729b85dbdb6c13b724b5d58fcd8e to your computer and use it in GitHub Desktop.
Save earlonrails/21d4729b85dbdb6c13b724b5d58fcd8e to your computer and use it in GitHub Desktop.
The Popular goat latin interview question
#!/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