iOS Closures in Swift First Class Functions Higher Order Functions

john lau
john lau
3,345 Points

get no idea why I can't pass it

no idea

functions.swift
// Enter your code below

extension String {

    func transform(_ aString: (String) -> String ) -> String {
        func removeVowels(from string: String) -> String {
            var newString = ""
            for character in string.characters {
                if ["a","e","i","o","u"].contains(character) {

                    newString.append(character)
                }


            }

            return newString
        }

        return(aString(self))
    }
}

2 Answers

Simon Di Giovanni
Simon Di Giovanni
8,428 Points

Hi John

Your code is fine, just take the function removeVowels out of the transform function, and put it directly into the extension. Try the below code to check if it works.

extension String {

    func transform(_ aString: (String) -> String ) -> String {
        return(aString(self))
    }


    func removeVowels(from string: String) -> String {
        var newString = ""
        for character in string.characters {
            if ["a","e","i","o","u"].contains(character) {
                newString.append(character)
            }
    }
}
john lau
john lau
3,345 Points

thks Simon it works!