Created
October 30, 2015 01:38
-
-
Save kkchu791/21301a4597b616523f0b 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 sort num | |
res= [] | |
res2= [] | |
arr = num.to_s.split("") | |
arr.each { |x| res << x.to_i } | |
big_array = res.permutation.to_a | |
big_array.each {|x| res2 << x.join.to_i } | |
p res2 | |
end | |
sort(123) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kirk,
Whenever someone asks me to write a function, I assume they mean I should return a value from that function, and not print out a value. I want to invite you to do the same with me -- return a value, don't print it.
Your solution is otherwise good, but I want to invite you to chain methods together, instead of storing temporary values in local variables.
I also want to invite you to follow the Github Ruby styleguide, which would have you put your arguments in parentheses:
def sort(num)
So altogether, something like this: