practice-problems-1/comments/00-reverse.rb
# 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.
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.

easy.
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 . easy .
def reverse(string) 
  answer = ""                 
  range = string.length-1     
  range.downto(0) do |i|    
    answer << string[i]     
  end
  return answer             
end
def reverse ( string ) answer = "" range = string . length - 1 range . downto ( 0 ) do | i | answer << string [ i ] end return answer end
Write a method that will take a string as input, and return a new
string with the same letters in reverse order.
Write a method that will take a string as input and return a new string with the same letters in reverse order .
#what will be returned. Also holds result during program #The '-1' is to compensate for array index. #Ex: "abc".length == 3 HOWEVER,"abc"[3] is a nil value. So when take away one you include the whole string. #loop from the end of the string to the beginning of the string. #gets the value, located at the given index, and add it to the empty string. #return answer at end
string
<not_specific>