Skip to content

Instantly share code, notes, and snippets.

@Fonsan
Created May 25, 2011 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fonsan/991667 to your computer and use it in GitHub Desktop.
Save Fonsan/991667 to your computer and use it in GitHub Desktop.
@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