回答編集履歴

1

update

2022/03/04 09:31

投稿

melian
melian

スコア19825

test CHANGED
@@ -2,16 +2,7 @@
2
2
  data = {:chocolate=>95, :ice=>90, :candy=>90}
3
3
  ref = {:candy=>0, :ice=>1, :chocolate=>2}
4
4
 
5
- p data.sort{|a,b|
5
+ p data.sort_by{|k,v| [-v, ref[k]]}
6
- case a[1] <=> b[1]
7
- when -1
8
- 1
9
- when 1
10
- -1
11
- when 0
12
- ref[a[0]] <=> ref[b[0]]
13
- end
14
- }
15
6
 
16
7
  #
17
8
  [[:chocolate, 95], [:candy, 90], [:ice, 90]]