iOS Closures in Swift First Class Functions Higher Order Functions

Luigi Santos
Luigi Santos
13,200 Points

How can I make this work?

This gives me no errors or warning in the playground. What am I doing wrong?

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 {

      } else {
        newString += String(char)
      }
    }

    return newString
  }

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

1 Answer

Luigi Santos
Luigi Santos
13,200 Points

Never mind, got it to work. Just thought it looked strange.

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