I want to sort an array of names first by frequency, then alphabetically, so the result will be:

Jack (4), Dan (3), Dave (3), Alex (2), Allen (2)

(The frequency number in parenthesis is just for reference, I don't need it to display.)

Currently what I'm doing is:

```
names = ["Jack", "Dan", "Jack", "Dan", "Jack", "Dan", "Jack", "Dave", "Alex", "Allen", "Dave", "Alex", "Dave", "Allen"]
subjects = names.uniq

freq = names.inject(Hash.new(0)) { |h, v| h[v] += 1; h }
subjects.sort_by {|v| [freq[v], v]}

```

The problem is that sorting just by frequency returns an array in ascending order (least frequent to most frequent) (i.e. Allen, Alex, Dan, Dave, Jack), while sorting just alphabetically goes from A to Z left-to-right (i.e. Alex, Allen, Dan, Dave, Jack). 

As a result, the two field sort is doing the opposite of what I want - it's sorting by frequency and then, essentially, by *reverse*-alphabetical order (so: Alex, Allen, Dan, Dave, Jack).

I have a clumsy way of reversing it by calculating "reverse frequency" (i.e. the most frequent name gets the *lowest* number instead of the highest), which does get me to the right result, but I feel like there has to be a better way of doing it than this:

```
freq = names.inject(Hash.new(0)) { |h, v| h[v] -= 1; h } # -= instead of +=
subjects.sort_by {|v| [freq[v], v]}

```