Created
February 19, 2014 10:50
-
-
Save emad-elsaid/9089725 to your computer and use it in GitHub Desktop.
convert integer to array in ruby
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
class Integer | |
def to_a | |
arr = [] | |
tmp = self | |
while tmp>0 | |
arr << tmp%10 | |
tmp /= 10 | |
end | |
arr.reverse | |
end | |
end | |
# usage | |
print 32455.to_a | |
print 433456.to_a | |
print 345434.to_a.sort | |
print 344543.to_a.join '-' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment