zjwang zjwang - 5 months ago 28
Ruby Question

How to apply a secondary sort for ruby array with reversed sort direction?

I have a ruby array in the format of


I know I can apply secondary sort using the following

sort_by{ |o| [o.name, o.score]}

However I want to sort first on Name asc and then sort on Score but descending. How could I achieve this?



You can easily do it with

sort_by{ |o| [o.name, -o.score]}