Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Looks good. If I were being picky I’d suggest that the input arguments should be lower case, and then you should uppercase the first one.
-
RayS991296y@joycestick This is to have an output of "Row, row, row your boat." basically you're saying to capitalize the first word being Row?
-
RayS991296y@joycestick Thanks so much! I have a habit of overthinking or over complicating and I try to keep it simple.
-
@RanSS9 It’s easily done. You could add loads of additional case checks etc. to this, but that’s not in the brief. That’s one of the hardest things as a developer - knowing how much to check and future proof, but knowing when to stop. I think you’ve judged this one well.
-
RayS991296y@joycestick Im still struggling with:
let line = openingLine(verb: "Row", noun: "Boat")
I think the "let line" is the part the throws me off. Why is it there? Is it just saying the line: openingLine(verb: "Row", noun: "Boat") is a constant line that reads as follows i.e. openingLine(verb: "Row", noun: "Boat") ?
I may be overthinking it but I don't get why they bother saying, "...the function should look like the let line" if "let line" part isn't in the function. It throws me off.
let line = openingLine(verb: "Row", noun: "Boat") -
@RanSS9 I think you just need to rename your function to openingLine. Then if someone wanted to use your function to get the opening line of the song and set it to a variable called line, then their line of code would be:
let line = openingLine(verb: "row", noun: "boat")
That line isn't actually in your function, it's an example of how they would call your function. -
RayS991296y@joycestick
func openingLine(verb: String, noun: String) -> String {
return "Row, \(verb), \(verb) your \(noun)."
}
openingLine(verb: "row", noun: "boat") -
@RanSS9 I don't think you should hardcode Row into the function, otherwise someone calling:
openingLine(verb: "drive", noun: "car")
would get:
Row, drive drive your car
My solution to the exercise would be:
func openingLine(verb: String, noun: String) -> String {
let lowerCaseVerb = verb.lowercased()
let lowerCaseNoun = noun.lowercased()
return "\(verb), \(lowerCaseVerb), \(lowerCaseVerb) your \(lowerCaseNoun)"
} -
RayS991296y@joycestick OMG thanks that was driving me nuts on how I should deal with that scenario.
Related Rants
I feel like I didn't do this right and I'm a tad confused as to what they mean when they say that the function should look like this when you call it:
let line = openingLine(verb: "row", noun: "boat")
Is my solution correct?
question
return
xcode
functions
swift