Sort an enumerable in descending order
enumerable, ruby
Solution
The performance of `Array.reverse` is not very bad. What costs you by using `@array.sort.reverse` is an extra array duplication plus the reverse (n/2 element switches). So yes, I think that should be acceptable if you think it's read clearer.
See its source for details. And also, I think using `@array.sort.reverse` does provide 'slightly' better readability (but it's not very hard to read any way).
Problem
What's the best way to sort an `Enumerable` in descending order? I've been doing `@array.sort.reverse` or `@array.sort_by{|song| song.title }.reverse` I suppose I could do something like `@array.sort{|a, b| b.title <=> a.title}`, but I find this hard to read and verbose.