Last active
August 29, 2015 14:16
-
-
Save aire-con-gas/4fdf0d6dcd51619bdbdb to your computer and use it in GitHub Desktop.
Text-related activities: reverse text and swap in place
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 Bigaqua | |
module Text | |
def reverse_text(input) | |
arr = [] | |
i = input.length - 1 | |
while i >= 0 do | |
arr.push(input[i]) | |
i -= 1 | |
end | |
arr.join("") | |
end | |
def swap_in_place(input) | |
length = input.length | |
mid = (length / 2) - 1 | |
for i in (0..mid) | |
tmp = input[i] | |
input[i] = input[-i-1] | |
input[-i-1] = tmp | |
end | |
input | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment