Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialABHINAV 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,969 PointsDaniel Santos
34,969 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?