So, I am stuck on this since most of the internal Swift programs don't work anymore and am still learning. I have tried a lot of things but it still doesn't work.
I have tried internal functions. I have tried custom methods. I have tried putting them in extensions (It is the same as custom methods but I wanted to practice extensions.)
extension Character {
var isVowel: Bool {
let vowels: [Character] = ["a", "e", "i", "o", "u"]
return vowels.contains(self)
}
}
extension String{
func transform (_ function: (String) -> String) -> String{
return function(self)
}
func toCharacter() -> [Character]{
var working = self.components(separatedBy: "")
var output: [Character] = []
for i in 0...working.count{
output.append(Character(working[i]))
}
return output
}
}
func toString(from input: [Character]) -> String{
var output = ""
for i in input{
output += String(i)
}
return output
}
func removeVowels(from given: String) -> String{
var working = given.toCharacter()
for i in 0...working.count{
if working[i].isVowel{
working.remove(at: i)
}
}
return toString(from: working)
}
In an extension to the String type, declare a function named transform. The function should accept as an argument another function of type (String) -> String. For this argument, let's omit the external label. The transform function should also return a String.
Create a function named removeVowels that takes a string and returns a string. Name the external argument label for the parameter from. In the body of the method, return a new String literal with the vowels (in the English language) removed from the value passed in as an argument.