回答編集履歴
2
Int
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
str.sort { Int($1[5])! < Int($0[5])! }
|
7
7
|
```
|
8
8
|
|
9
|
-
#
|
9
|
+
# Int以外の文字列が入る可能性がある場合
|
10
10
|
|
11
11
|
その文字列を0としてソートします。
|
12
12
|
|
1
\?\?
answer
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
+
# 必ず数値が入っている場合
|
2
|
+
|
1
3
|
Intに変換して比較します。
|
2
4
|
|
3
5
|
```swift
|
4
6
|
str.sort { Int($1[5])! < Int($0[5])! }
|
5
|
-
```
|
7
|
+
```
|
8
|
+
|
9
|
+
# 数値以外の文字列が入る可能性がある場合
|
10
|
+
|
11
|
+
その文字列を0としてソートします。
|
12
|
+
|
13
|
+
```swift
|
14
|
+
str.sort { Int($1[5]) ?? 0 < Int($0[5]) ?? 0 }
|
15
|
+
```
|