Last active
August 29, 2015 14:17
-
-
Save tdg5/78a7b7251c33b8543969 to your computer and use it in GitHub Desktop.
itoa method
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
def itoa(int, base = 10) | |
str = "" | |
while int > 0 | |
str = ((int % base) + 48).chr + str | |
int /= base | |
end | |
str | |
end | |
def itoarr(int, base = 10) | |
str = [] | |
while int > 0 | |
str.unshift(((int % base) + 48).chr) | |
int /= base | |
end | |
str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment