Last active
February 20, 2019 20:42
-
-
Save alessandrostein/f28375bfe7431b4c523a006874105b18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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