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 trial

iOS Closures in Swift First Class Functions Higher Order Functions

Taylor Smith
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Taylor Smith
iOS Development Techdegree Graduate 14,153 Points

compiles perfectly in a playground...but I can't pass the challenge. what am I doing wrong? Closures Task 3 of 3

functions.swift
extension String {

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

        return function(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
}

let result = "Hello World!".transform(removeVowels)

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello :

Your string looks like "Hello World!" missing a comma.

Here is an example of what you could do:

extension String {

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

}

func removeVowels(from: String) -> String {
    var output = ""

    for vowel in from.characters {

        if ["a","e","i","o","u"].contains(vowel){
            continue // If the vowel is in this array, it will continue the loop
        } else {
            output.characters.append(vowel) 
        }

    }
    return output
}

let result = "Hello, World!".transform(removeVowels)

Good luck