Skip to content

Instantly share code, notes, and snippets.

@naoto
Created May 13, 2010 04:20
Show Gist options
  • Save naoto/399487 to your computer and use it in GitHub Desktop.
Save naoto/399487 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
str = "abcde"
cnt = str.length - 1
rev = []
str.split(//).each { |c|
rev[cnt] = c
cnt = cnt - 1
}
puts rev.to_s
#!/usr/bin/env ruby
def reverse(str,rev = [])
rev << str.pop
reverse(str,rev) if !str.empty?
rev.to_s
end
str = "abcde".split(//)
str_rev = reverse(str)
puts str_rev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment