Issue #8422 has been updated by marcandre (Marc-Andre Lafortune).


matz (Yukihiro Matsumoto) wrote:
> It can be done by a.sort{|a,b| b<=>a}.

That will typically be much slower though.

Currently, the best way to do a reverse sort, performance-wise, is  `a.sort.reverse!`

For a random 100 number array, for example:

sort.reverse! is faster than sort.reverse by 10% 賊 1.0%
sort.reverse is faster than sort_by by 6x 賊 0.1
sort_by is faster than sort by 60% 賊 1.0%

Code: https://gist.github.com/marcandre/5604592 


----------------------------------------
Feature #8422: add Enumerable#reverse_sort and Enumerable#reverse_sort_by
https://bugs.ruby-lang.org/issues/8422#change-39424

Author: Hanmac (Hans Mackowiak)
Status: Feedback
Priority: Normal
Assignee: 
Category: 
Target version: 


they are better when you want descending order,
  enum.sort.reverse
does work too, but it is to slow because it needs to build that result array twice

they both can be defined just like #sort and #sort_by but negates the result of the compare block


-- 
http://bugs.ruby-lang.org/