Created
August 7, 2013 03:48
-
-
Save scarow/6171042 to your computer and use it in GitHub Desktop.
Pig latin keeping punctuation
This file contains 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 pig_latin word | |
results_array = Array.new | |
counter = 0 | |
vowels = ["a","e","i","o","u"] | |
if word.downcase[0] != ("a" || "e" || "i" || "o" || "u") | |
split_word = word.split(//) | |
split_word.each do |current_letter| | |
if vowels.include?(current_letter) | |
break | |
else | |
counter += 1 | |
end | |
end | |
else | |
return word + "ay" | |
end | |
split_word.rotate(counter).join() + "ay" | |
end | |
def pig_latin_sentence | |
p "Type your sentence" | |
sentence = gets.chomp | |
punctuation = sentence.scan(/\W/) | |
words = sentence.split(/\W/) | |
p punctuation | |
p words | |
answer = words.map! do |x| | |
p pig_latin x | |
end | |
p answer.zip(punctuation).join("").downcase.capitalize | |
end | |
pig_latin_sentence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment