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

eberhapa
eberhapa
51,495 Points

Closures Challenge

I'm stuck with Challenge Task 2 of 3 of the Closures 2017 course.

The code is working perfect in the playground but i can't pass the challenge. Whats the issue?

functions.swift
// Enter your code below
extension String {
  func transform(_ function: (String) -> String) -> String {
    return function(self)
  }
}

extension Character {
    var isVowel: Bool {
        let vowels: [Character] = ["a", "e", "i", "o", "u"]
        return vowels.contains(self)
    }
}

func removeVowels(from string: String) -> String {
    var newString = ""
    for char in string.characters {
        if char.isVowel {
            newString += String(char)
        }
    }
    return newString
}

1 Answer

andren
andren
28,558 Points

You seem to have misunderstood the objective of the task. The removeVowels function is supposed to remove the vowels from the string it is given and then return a string without vowels. Your code does the exact opposite. In addition it only deals with lower case letters. It would fail if the string contained an uppercase vowel.

eberhapa
eberhapa
51,495 Points

Thank you :)