
ABHINAV VERMA
6,033 PointsIssue in resolving this function
When I'm implementing this function without adding an external parameter everything works in the removeVowels function as expected, but it doesn't with an external parameter as the input isn't being cast as a (String) -> String rather just as a String. how do I resolve this issue
// Enter your code below
extension String{
func transform (_ retString: (String) -> String) -> String {
return retString(self)
}
}
func removeVowels(from string: String) -> String {
var string1 = string.lowercased()
let vowels: [Character] = ["a", "e", "i", "o", "u"]
let result = String(string1.characters.filter { !vowels.contains($0) })
return result
}
let result = "Hello, World!".transform(removeVowels)
1 Answer

ABHINAV VERMA
6,033 PointsThe above is the exact code . I also tried to change the last line
let result = "Hello,World!".transform(removeVowels(from: "Hello, World")) but that was giving a cast error
Daniel Santos
34,700 PointsDaniel Santos
34,700 PointsI tried this with and without external parameter, and both worked. Can you help me reproduced the problem that you have? Can you post exactly the code you are running, if is not the one above?