-
-
Save Pasanpr/26e6e6227e62b7330a09a825c02a612f to your computer and use it in GitHub Desktop.
Determine if a character is a vowel or not
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
extension Character { | |
var isVowel: Bool { | |
let vowels: [Character] = ["a", "e", "i", "o", "u"] | |
return vowels.contains(self) | |
} | |
} |
'characters' is deprecated in the newer versions of swift thus removeVowels function should:
func removeVowels(from value: String) -> String {
return String(value.filter { !["a", "e", "i", "o", "u"].contains($0) })
}
extension Character
{
var isVowel: Bool {
return "aeiou".contains(self)
}
}
func removeVowels(from: String) -> String
{
return from.filter { !$0.isVowel }
}
func removeVowels(from mystring: String) -> String {
let vowels:[Character] = ["a","e","i","o","u","y"]
var output = ""
for a in mystring {
if vowels.contains(a) != true {
output += String(a)
}
}
return output
}
func removeVowels(from value: String) -> String {
var vowels: [Character] = ["a", "e", "i", "o", "u"]
var newValue = value.lowercased()
newValue.removeAll(where: { vowels.contains($0) })
return newValue
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added the uppercased versions to the Character Extension, as well as an isConsonant that just piggy backs off of isVowel so you don't have to loop through all the other characters.