Created
January 28, 2016 11:22
-
-
Save psylone/90dd7746db15a1e1d8c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse(string) | |
# gets (input from STDIN) isn't necessary cause you get string argument in this method | |
# input = gets.strip | |
# You should split your string by empty string to get an array of it's chars | |
string_array = string.split('') | |
# Class name should be started from a capital letter | |
new_word = Array.new | |
# You get only last letter here, but it's probably should be in loop | |
# last_letter = string_array.pop | |
# | |
# if string_array.length > 0 | |
# new_word.push(last_letter) | |
# else return new_word.join | |
# end | |
while letter = string_array.pop | |
new_word.push(letter) | |
end | |
# In Ruby you can ommit return keyword if you just want to return the last value | |
new_word.join | |
end | |
p reverse("Look at me, I am reversed!") # => "!desrever ma I ,em ta kooL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment