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
Daniel Hunter
7,349 PointsReverse Function
I'm trying to have the function FirstReverse(flip) take the flip parameter being passed and return the string in reversed order.
Here's what I have so far:
def FirstReverse(flip)
flip = flip.reverse
return flip
end
Daniel Hunter
7,349 PointsOh ok gotcha, this was something I was running offline. Wasn't sure if it was correct.
Geoff Parsons
11,679 PointsCouple of comments about your code Daniel Hunter
- Method names should start with a lowercase letter; it'll work as you have it but isn't idiomatic ruby.
- You wouldn't need the return call here as ruby methods always return the value of the last evaluated statement.
- Likewise the assignment isn't needed either as
flip.reversewould be evaluated and returned.
Putting those notes together a more idiomatic ruby version of this method would look like this:
def first_reverse(flip)
flip.reverse
end
Daniel Hunter
7,349 PointsOk gotcha, thanks Geoff!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Daniel,
Is this from a code challenge?
What problem are you having?
Your code seems to do what you want it to do.