Created
November 20, 2018 03:59
-
-
Save RickArora/71529d14e7b812c438dfe1ddf138566d to your computer and use it in GitHub Desktop.
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 devowel(str) | |
vowels = ["a", "e", "i", "o", "u"] | |
new_str = "" | |
# We turn the string into an array of characters using chars. | |
# An alternative to this is the method each_char (covered below!) | |
str.chars.each do |ch| | |
next if vowels.include?(ch.downcase) | |
# the code below is only reachable when ch is a consonant | |
new_str += ch | |
end | |
new_str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment