我有一个哈希数组:
a = [
{ :id => 10, :name => 'bush' },
{ :id => 2, :name => 'sugar' },
{ :id => 10, :name => 'mountain' },
{ :id => 10, :name => 'bug' },
{ :id => 8, :name => 'sugar' }
]
我想先按 id 升序对数组进行排序,然后按名称按字母降序对数组进行排序,这样最终结果将是:
a = [
{ :id => 2, :name => 'sugar' },
{ :id => 8, :name => 'sugar' },
{ :id => 10, :name => 'mountain' },
{ :id => 10, :name => 'bush' },
{ :id => 10, :name => 'bug' }
]
我如何实现这一目标?