iOS Closures in Swift First Class Functions Higher Order Functions

Nan Wang
Nan Wang
10,036 Points

Create a function named removeVowels that takes a string and returns a string. Name the external argument label for the

This is my code, i dont know why it is not passing :( please help :(

extension String {

func transform(_ arguement:(String) -> String) -> String {

    return arguement(self)

}


func removeVowels(from value:String) -> String {

    var output = ""
    for char in value.characters {

        if !(char == "a" || char == "A" || char == "e" || char == "E" || char == "I" || char == "i" || char == "o" || char == "O" || char == "u" || char == "U") {
            output.append(char)
        }
    }
    return output

}

}

functions.swift
// Enter your code below

extension String {

    func transform(_ arguement:(String) -> String) -> String {

        return arguement(self)

    }


        func removeVowels(from value:String) -> String {

        var output = ""
        for char in value.characters {

            if !(char == "a" || char == "A" || char == "e" || char == "E" || char == "I" || char == "i" || char == "o" || char == "O" || char == "u" || char == "U") {
                output.append(char)
            }
        }
        return output

    }

    }

2 Answers

Jennifer Nordell
MOD
Jennifer Nordell
Treehouse Moderator

Hi there! Your function is fine, but is defined inside the extension instead of outside. When I move the last curly brace in your code up so that it closes off the extension, your code passes the second step of the challenge! Hope this helps! :sparkles:

Qasa Lee
Qasa Lee
18,904 Points
[Moderator redacted]

This may help, good luck!

Michael Hulet
Michael Hulet
Treehouse Moderator 46,564 Points

Hey Qasa! It's frowned upon in the community to post answers with code that can be copied and pasted to pass a challenge, especially without explanation. In the future, post code snippets that illustrate the way to accomplish the task that OP is trying to solve, but make sure that the code you post can't be copied and pasted into the challenge and pass without modification. Furthermore, be sure to give a thorough explanation about why that code is the proper method to solve the problem and how the code works, so that both OP and anyone else who comes across the question can learn and have an understanding about how to solve similar problems in the future. I've redacted the code in your answer accordingly, but feel free to re-post something similar with an explanation about why and how it does the trick. Thanks for helping out in the community!