Skip to content

Instantly share code, notes, and snippets.

@jonvuri
Created November 22, 2012 00:08
Show Gist options
  • Save jonvuri/4128647 to your computer and use it in GitHub Desktop.
Save jonvuri/4128647 to your computer and use it in GitHub Desktop.
Pig Latin Refinement
def translate(pigstri)
vowels = [ "a", "e", "i", "o", "u", "y" ]
pigstri
.split(/ /, -1)
.map { |x|
first_vowel = x.chars.find_index { |x| vowels.include?(x) }
if vowels.include?(x[0])
x + "ay"
elsif x[0..1].include?("qu")
x[2..x.length] + x[0..1] + "ay"
else
x[first_vowel..-1] + x[0..(first_vowel - 1)] + "ay"
end
}.join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment