Skip to content

Instantly share code, notes, and snippets.

@aire-con-gas
Last active August 29, 2015 14:16
Show Gist options
  • Save aire-con-gas/4fdf0d6dcd51619bdbdb to your computer and use it in GitHub Desktop.
Save aire-con-gas/4fdf0d6dcd51619bdbdb to your computer and use it in GitHub Desktop.
Text-related activities: reverse text and swap in place
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