Write a method that will take a string as input, and return a new
string with the same letters in reverse order.
Don’t use String’s reverse method; that would be too simple.
Difficulty: easy.
def reverse(string)
input = gets.strip
string_array = string.split(,)
new_word = array.new
last_letter = string_array.pop
if string_array.length > 0
new_word.push(last_letter)
else return new_word.join
end
end
When I debug in mac terminal, i get the following:
reverse(help)
/users/cyrilguirguis/Desktop/reverse.rb:17:in reverse': undefined method
push’ for “)”:String (NoMethodError)
from /users/cyrilguirguis/Desktop/reverse.rb:25:in `’
I’m looking to review my code and provide a hint if my code is not
correct, and help me debug this specific nomethoderror problem.
Thank you for your time!