Skip to content

Instantly share code, notes, and snippets.

@charlieegan3
Created December 9, 2014 22:52
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 charlieegan3/8c6faa8804ca5b1a1fc8 to your computer and use it in GitHub Desktop.
Save charlieegan3/8c6faa8804ca5b1a1fc8 to your computer and use it in GitHub Desktop.
sorted_dup_hash
def sorted_dup_hash(array)
Hash[*array.inject(Hash.new(0)) { |h,e| h[e] += 1; h }.
select { |k,v| v > 1 }.inject({}) { |r, e| r[e.first] = e.last; r }.
sort_by {|_,v| v}.reverse.flatten]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment