
eberhapa
51,495 PointsClosures Challenge
I'm stuck with Challenge Task 2 of 3 of the Closures 2017 course.
The code is working perfect in the playground but i can't pass the challenge. Whats the issue?
// Enter your code below
extension String {
func transform(_ function: (String) -> String) -> String {
return function(self)
}
}
extension Character {
var isVowel: Bool {
let vowels: [Character] = ["a", "e", "i", "o", "u"]
return vowels.contains(self)
}
}
func removeVowels(from string: String) -> String {
var newString = ""
for char in string.characters {
if char.isVowel {
newString += String(char)
}
}
return newString
}
1 Answer

andren
28,479 PointsYou seem to have misunderstood the objective of the task. The removeVowels
function is supposed to remove the vowels from the string it is given and then return a string without vowels. Your code does the exact opposite. In addition it only deals with lower case letters. It would fail if the string contained an uppercase vowel.
eberhapa
51,495 Pointseberhapa
51,495 PointsThank you :)