Skip to content

Instantly share code, notes, and snippets.

@adillera
Created October 16, 2013 10:13
Show Gist options
  • Save adillera/7005589 to your computer and use it in GitHub Desktop.
Save adillera/7005589 to your computer and use it in GitHub Desktop.
One possible solution to the pig latin problem. It takes only lower cased words and a group of words.
def pig_latin(s)
vowels = %w(a e i o u)
words = s.split(' ')
@new_sentence = String.new
words.each_with_index do |w, i|
if vowels.include? w[0]
word = w + 'way'
word = i == (words.count - 1) ? word : word + ' '
@new_sentence << word
else
first_vowel = w.index(/[aeiou]/)
word = w[first_vowel..-1] + w[0..(first_vowel - 1)]
word = word + 'ay'
word = i == (words.count - 1) ? word : word + ' '
@new_sentence << word
end
end
@new_sentence
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment