irclog.perlgeek.de/perl6book/today | source: github.com/perl6/book/
Set by moderator on 30 September 2011.
15:31 smash joined 18:04 Doctor_Pi joined 18:21 Entonian joined
Entonian my @sorted = @names.sort( { %sets{$_} }).sort({ %matches{$_} }).reverse; 18:26
Shouldn't there be a reverse on the sort by sets, too?
Util Entonian: With the code as written, the output is: 18:49
Ana has won 2 matches and 8 sets
Dave has won 2 matches and 6 sets
Charlie has won 1 matches and 4 sets
Beth has won 1 matches and 4 sets
Changing the code to @names.sort( { %sets{$_} }).reverse.sort({ %matches{$_} }).reverse , we get:
Dave has won 2 matches and 6 sets
Ana has won 2 matches and 8 sets
Beth has won 1 matches and 4 sets
Charlie has won 1 matches and 4 sets
So, No, there should not be an extra reverse. 18:50
The .reverse method does not instruct .sort to sort in descending order, it just takes the list it is given and reverses the list order.
After the two sorts, the list is ordered by ascending-primary-key and ascending-secondary-key.
Reversing at that point makes the list is ordered by descending-primary-key and descending-secondary-key.
Entonian Util: Thank you
Util Glad to help!