iOS Closures in Swift First Class Functions Higher Order Functions

Vansh Agarwal
PRO
Vansh Agarwal
Pro Student 3,964 Points

Code not getting accepted

Hi, can someone tell me why my code is not working for the code challenge? Thanks!

functions.swift
// Enter your code below

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

   func removeVowels(from string: String) -> String
    {
    var output = ""
    for char in string.characters 
    {
    if !(char ==  "a" || char ==  "e" || char ==  "i" || char ==  "o" || char ==  "u" || char ==  "A" || char ==  "E" || char ==  "I" || char ==  "O" || char ==  "U")
    {
    output.append(char)
    }
    }
    return output
    }
}

1 Answer

Jeff McDivitt
Jeff McDivitt
23,959 Points

Hi Vansh - You are missing calling the transform function to remove the vowels

On the string "Hello, World!", call the transform function and use the removeVowels(from:) function as an argument. Assign the result to a constant named result.

"Hello, World!".transform(removeVowels)