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
MOD
andren
Treehouse Moderator 28,308 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 :)