Skip to content

Instantly share code, notes, and snippets.

@josiah14
Last active August 29, 2015 14:20
Show Gist options
  • Save josiah14/e6bc62ffe762a0228ea8 to your computer and use it in GitHub Desktop.
Save josiah14/e6bc62ffe762a0228ea8 to your computer and use it in GitHub Desktop.
reverse_string
def reverse_str(str)
str.split('').tap do |str_ary|
len = str_ary.length
(0..len / 2).each do
left = i
right = len - i - 1
str_ary[left], str_ary[right] = str_ary[right], str_ary[left]
end
str_ary.reduce(:+)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment