Created
November 1, 2016 14:33
-
-
Save FsDevNinja/dbace853ed558860e3bd72967a6c00be to your computer and use it in GitHub Desktop.
Reverse a string in ruby without using .reverse
This file contains hidden or 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
module StringReverser | |
def self.reverse(input) | |
return nil if input == nil | |
output = [] | |
input.split("").each_with_index do |n,i| | |
output << input[-i-1] | |
end | |
output.join("").to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment