I'm doing a problem where I'm asked to reverse a string without using the .reverse method. Below is the solution and I'm not sure why it works. The way I'm reading it is - I'm creating an empty array named reverse_string. while i is less than the length of the existing string, the program will add a letter from the existing string and..what exactly? I suppose what I'm trying to say is I don't know how to read the below in a way that makes sense.
def reverse(string) reverse_string = "" i = 0 while i < string.length reverse_string = string[i] + reverse_string i+=1 end return reverse_string end
Replace this line with your code.