iOS Closures in Swift First Class Functions Higher Order Functions

Jeevan Thandi
Jeevan Thandi
748 Points

"Make sure removeVowels accepts a string and returns a string" Code works in playground but won't run in coding window?

Output.html is blank, code works in playground, doesn't seem to work on the site, any ideas?

// Enter your code below

extension String {

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

func removeVowels(from value: String) -> String {
      let vowels = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]

    return String(value.characters.filter { !vowels.contains("\($0)") })


1 Answer

Jhoan Arango
Jhoan Arango
Treehouse Moderator 12,181 Points


Just put the function outside of the "String" extension. Right now is a method, it should be a function. A function does not belong to a type, a method is a function that belongs in a type such as class or struct.

Give it a try.