Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

26 lines (16 sloc) 0.744 kb
#reversing a string without using reverse method. June 20, 2012
#wrote this into a string method. It's in the same file.
#
# the variables. a forward string
#the backward empty string.
#the holding array
forwards = "hello this is a string. In a moment it will be reversed without using the 'reverse' method."
backwards = ""
holding_array = []
#put the string in the array
forwards.each_char {|letter| holding_array.push(letter)}
#it's first in first out. We push the letters one by one into an array. then we pop them back out into the backwards string
holding_array.length.times {|letters| backwards << holding_array.pop}
puts forwards
puts backwards
puts "this is the same string using the reverse method----->" + forwards.reverse
Jump to Line
Something went wrong with that request. Please try again.