Skip to content

Instantly share code, notes, and snippets.

@alessandrostein
Last active February 20, 2019 20:42
Show Gist options
  • Save alessandrostein/f28375bfe7431b4c523a006874105b18 to your computer and use it in GitHub Desktop.
Save alessandrostein/f28375bfe7431b4c523a006874105b18 to your computer and use it in GitHub Desktop.
def reversal!(text)
textVowels = getVowels(text)
textReversal = ""
vowelPosition = 0
for j in 0..text.size - 1 do
if isVowel(text[j])
vowelPosition += 1
if vowelPosition == textVowels.size
textReversal << textVowels[0]
else
textReversal << textVowels[vowelPosition]
end
else
textReversal << text[j]
end
end
puts textReversal
end
def getVowels(text)
textVowels = ""
for i in 0..text.size - 1 do
textVowels << text[i] if isVowel(text[i])
end
textVowels
end
def isVowel(char)
vowes = ["a", "e", "i", "o", "u"]
vowes.include?(char)
end
reversal!("apple")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment