array = %w[a b a b c d e g j a e c d k o k i l p a e c f d e a d e f s d v c ]
result = Hash[array.each_with_object(Hash.new(0)) {|e, h| h[e] += 1 }.sort_by {|k,v| -v}].keys
array = %w[a b a b c d e g j a e c d k o k i l p a e c f d e a d e f s d v c ]
array.sort_by {|v| -array.count(v)}.uniq