Created
May 25, 2011 19:13
-
-
Save Fonsan/991667 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
@samples = 10.times.map do rand(10) end | |
result = @samples.inject( Hash.new(0) ) do |hash,element| | |
hash[element] += 1 | |
hash | |
end.to_a # => [[6, 3], [3, 1], [1, 1], [9, 2], [4, 2], [8, 1]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment