Here’s the code I have which takes a string and reverse it
name = "I CAN REVERSE THIS"
def reverse_string(name_string)
string_arr = []
string_arr = name_string.split('')
for i in 1..(string_arr.length)
new_string = "#{new_string}#{string_arr[-i]}"
end
#return new_string
end
new_name = reverse_string(name)
puts new_name
Why does my reverse_string function returns “1..18” if no return actions is called inside the function, but returns expected results if return action is called?
In Ruby, a method’s implicit return value (if no explicit call to
returnis being made) is the return value of the last statement in that method. In this case that is thefor, which apparently returns what it iterated over.