Skip to content

Instantly share code, notes, and snippets.

@WhereIsX
Created March 15, 2019 02:30
Show Gist options
  • Save WhereIsX/eb1c6ccf8de7aae8cc2ff3e7f1350458 to your computer and use it in GitHub Desktop.
Save WhereIsX/eb1c6ccf8de7aae8cc2ff3e7f1350458 to your computer and use it in GitHub Desktop.
pig latinizer
require 'pry'
class PigLatinizer
def piglatinize(input)
# pig-latinizes for more than one word
# for piglatinizer of individual words, see scramble
# binding.pry
input.split.collect{ |word| scramble(word) }.join(" ")
end
def scramble(word)
# takes in one word, pig-latinizes it
# => #head is an array of chars before the first vowel of word
# => if first char of word == vowel, head = []
head = head(word)
if head == []
return word + "way"
else
return tail(word) + head.join + "ay"
end
end
def head(word)
# head should be composed of only constatants
# otherwise head = []
chars = word.split("")
head = []
chars.each do |char|
if !is_vowel?(char)
head << char
else
return head
end
end
end
def tail(word)
tail = word[(head(word).count)..-1]
end
def is_vowel?(char)
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
vowels.include?(char)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment