Skip to content

Instantly share code, notes, and snippets.

@RickArora
Created November 20, 2018 03:59
Show Gist options
  • Save RickArora/71529d14e7b812c438dfe1ddf138566d to your computer and use it in GitHub Desktop.
Save RickArora/71529d14e7b812c438dfe1ddf138566d to your computer and use it in GitHub Desktop.
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