Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created June 5, 2020 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshallmurphy/45c3c5eea21850918be08c3466eabfac to your computer and use it in GitHub Desktop.
Save marshallmurphy/45c3c5eea21850918be08c3466eabfac to your computer and use it in GitHub Desktop.
def reverse!(str)
arrayOfChars = str.split('')
index_left = 0
index_right = arrayOfChars.length - 1
while index_left < index_right
arrayOfChars[index_left], arrayOfChars[index_right] = \
arrayOfChars[index_right], arrayOfChars[index_left]
index_left += 1
index_right -= 1
end
return arrayOfChars.join('')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment