Created
May 13, 2010 04:20
-
-
Save naoto/399487 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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