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

Vansh Agarwal
PLUS
Vansh Agarwal
Courses Plus Student 3,965 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,970 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)