Perl 6 (36 bytes, 35 characters)
»
can be replaced with >>
, if you cannot handle UTF-8. I'm almost sure this could be shorter, but the Bag
class is relatively strange in its behavior (sadly), and isn't really complete, as it's relatively new (but it can count arguments). {}
declares an anonymous function.
{(sort -*.value,pairs bag @_)».key}
Sample output (from Perl 6 REPL):
> my @names = ("John","Doe","Dick","Harry","Harry","Doe","Doe","Harry","Doe","John")
John Doe Dick Harry Harry Doe Doe Harry Doe John
> {(sort -*.value,pairs bag @_)».key}(@names)
Doe Harry John Dick