質問編集履歴

3

追加

2020/05/07 04:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -77,3 +77,117 @@
77
77
  }
78
78
 
79
79
  ```
80
+
81
+
82
+
83
+ ```swift
84
+
85
+ let aArray_nilAble: [Int]? = [Int](0...100)
86
+
87
+ let bArray = [Int](200...300)
88
+
89
+
90
+
91
+ func hoge() -> Bool {
92
+
93
+
94
+
95
+ guard let aArray = aArray_nilAble else { return false }
96
+
97
+
98
+
99
+ return !aArray.filter(bArray.contains).isEmpty
100
+
101
+
102
+
103
+ // 重複あり[(0...100)-(50...150)]: 0.22072505950927734
104
+
105
+ // 重複なし[(0...100)-(200...300)]: 0.30579400062561035
106
+
107
+ }
108
+
109
+
110
+
111
+ func fuga() -> Bool {
112
+
113
+
114
+
115
+ guard let aArray = aArray_nilAble else { return false }
116
+
117
+
118
+
119
+ return aArray.contains(where: bArray.contains)
120
+
121
+
122
+
123
+ // 重複あり[(0...100)-(50...150)]: 0.1724480390548706
124
+
125
+ // 重複なし[(0...100)-(200...300)]: 0.3085750341415405
126
+
127
+ }
128
+
129
+
130
+
131
+ func piyo() -> Bool {
132
+
133
+
134
+
135
+ guard let aArray = aArray_nilAble else { return false }
136
+
137
+ let aSet = Set(aArray)
138
+
139
+ let bSet = Set(bArray)
140
+
141
+
142
+
143
+ return !(aSet.isDisjoint(with: bSet))
144
+
145
+
146
+
147
+ // 重複あり[(0...100)-(50...150)]: 0.17476892471313477
148
+
149
+ // 重複なし[(0...100)-(200...300)]: 0.1812349557876587
150
+
151
+ }
152
+
153
+
154
+
155
+ // 100回繰り返す
156
+
157
+ func repeatProcess() {
158
+
159
+
160
+
161
+ for _ in 1...100 {
162
+
163
+ print(piyo())
164
+
165
+ }
166
+
167
+
168
+
169
+ }
170
+
171
+
172
+
173
+ // 計測
174
+
175
+
176
+
177
+ let start = Date()
178
+
179
+
180
+
181
+ repeatProcess()
182
+
183
+
184
+
185
+ let elapsed = Date().timeIntervalSince(start)
186
+
187
+
188
+
189
+ print(elapsed)
190
+
191
+
192
+
193
+ ```

2

訂正

2020/05/07 04:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -42,6 +42,10 @@
42
42
 
43
43
 
44
44
 
45
+ エラーがでます
46
+
47
+
48
+
45
49
  ```swift
46
50
 
47
51
 

1

追加

2020/05/06 02:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,37 @@
39
39
 
40
40
 
41
41
  ```
42
+
43
+
44
+
45
+ ```swift
46
+
47
+
48
+
49
+ // 面倒なので[int]で、
50
+
51
+ let indexPaths = [1, 2, 3, 4]
52
+
53
+ let selectedRowsIndexPaths = [6, 7, 8, 9]
54
+
55
+
56
+
57
+
58
+
59
+ func hoge() -> Bool {
60
+
61
+ indexPaths.forEach{
62
+
63
+ if selectedRowsIndexPaths.contains($0) {
64
+
65
+ return true // <= error / Unexpected non-void return value in void function
66
+
67
+ }
68
+
69
+ }
70
+
71
+ return false
72
+
73
+ }
74
+
75
+ ```