Created
June 5, 2020 14:16
-
-
Save marshallmurphy/45c3c5eea21850918be08c3466eabfac to your computer and use it in GitHub Desktop.
This file contains 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
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