回答編集履歴
3
sort_by→max_by
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ary = %w[blue red red green blue red]
|
4
4
|
|
5
|
-
puts ary.group_by(&:itself).
|
5
|
+
puts ary.group_by(&:itself).max_by{|_, v| v.size}[0]
|
6
6
|
|
7
7
|
```
|
8
8
|
|
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
ary = %w[blue red red green blue red]
|
18
18
|
|
19
|
-
puts ary.tally.
|
19
|
+
puts ary.tally.max_by(&:last)[0]
|
20
20
|
|
21
21
|
```
|
22
22
|
|
2
修正
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ary = %w[blue red red green blue red]
|
4
4
|
|
5
|
-
puts
|
5
|
+
puts ary.group_by(&:itself).sort_by{|_, v| v.size}[-1][0]
|
6
6
|
|
7
7
|
```
|
8
8
|
|
1
修正
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ary = %w[blue red red green blue red]
|
4
4
|
|
5
|
-
puts p ary.group_by(&:itself).sort_by{|_, v| v.size}
|
5
|
+
puts p ary.group_by(&:itself).sort_by{|_, v| v.size}[-1][0]
|
6
6
|
|
7
7
|
```
|
8
8
|
|