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 trialKieran Tross
8,266 PointsIn an extension to the String type, add a function named modify. The modify function should accept as an argument a func
This is what I have so far.
extension String {
func modify(argument: String) -> String {
return self.modify("argument here")
}
}
Does anyone know the answer?
// Enter your code below
extension String {
func modify(argument: String) -> String {
return self.modify("argument here")
}
}
3 Answers
Alexander Smith
10,476 PointsThis is the first part of challenge. Forgot how confusing closures are
// Enter your code below
extension String {
func modify(argument: String -> String) -> String {
return argument(self)
}
}
Alexander Smith
10,476 PointsHeres the rest if you need it.
// Enter your code below
extension String {
func modify(argument: String -> String) -> String {
return argument(self)
}
}
func firstLetter(input: String) -> String {
return String(input.characters.first!)
}
let aString = "Swift"
let value = aString.modify(firstLetter)
Christopher Mayfield
19,928 PointsAre you unwrapping it because its an optional? Did you know it was optional because you looked at the documentation?
Abdoulaye Diallo
15,863 Pointstry to use this.
extension String { func transform(_ argc: (String) -> String ) -> String { return argc(self) }
}