/
FreeCoding.json
296 lines (296 loc) · 30.8 KB
/
FreeCoding.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
[
{
"question": "Write a function that accepts two strings and returns true if they are both the same regardless of what letter case they use.",
"hint": "If you make both strings lowercased using <code>lowercased()</code> you can compare the lowercased versions.",
"startingCode": "",
"answers": [
"func myFunction(input1:String,input2:String) -> Bool{\noptionalreturn input1.lowercased() == input2.lowercased()\n}",
"func myFunction(input1:String,input2:String) -> Bool{\noptionalreturn input1.uppercased() == input2.uppercased()\n}",
"func myFunction(input1:String,input2:String) -> Bool{\noptionalreturn !(input1.lowercased() != input2.lowercased())\n}",
"func myFunction(input1:String,input2:String) -> Bool{\noptionalreturn !(input1.uppercased() != input2.uppercased())\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool = input1.lowercased() == input2.lowercased()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool\nresult = input1.lowercased() == input2.lowercased()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool = input1.uppercased() == input2.uppercased()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool\nresult = input1.uppercased() == input2.uppercased()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool = input1.lowercased() != input2.lowercased()\nreturn !result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool\nresult = input1.lowercased() != input2.lowercased()\nreturn !result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool = input1.uppercased() != input2.uppercased()\nreturn !result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nletvar result:Bool\nresult = input1.uppercased() != input2.uppercased()\nreturn !result\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.lowercased() == input2.lowercased(){\nreturn true\n}else{\nreturn false\n}\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.lowercased() == input2.lowercased(){\nreturn true\n}\nreturn false\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nguard input1.lowercased() == input2.lowercased() else { return false }\nreturn true\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.uppercased() == input2.uppercased(){\nreturn true\n}else{\nreturn false\n}\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.uppercased() == input2.uppercased(){\nreturn true\n}\nreturn false\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nguard input1.uppercased() == input2.uppercased() else { return false }\nreturn true\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.lowercased() != input2.lowercased(){\nreturn false\n}else{\nreturn true\n}\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.lowercased() != input2.lowercased(){\nreturn false\n}\nreturn true\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nguard input1.lowercased() != input2.lowercased() else { return true }\nreturn false\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.uppercased() != input2.uppercased(){\nreturn false\n}else{\nreturn true\n}\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nif input1.uppercased() != input2.uppercased(){\nreturn false\n}\nreturn true\n}",
"func myFunction(input1:String,input2:String) -> Bool{\nguard input1.uppercased() != input2.uppercased() else { return true }\nreturn false\n}"
]
},
{
"question": "Write a function that accepts two strings and returns them joined together. For example, sending in the strings 'car' and 'pet' should return 'carpet'.",
"hint": "You can use <code>+</code> to join two strings together.",
"startingCode": "",
"answers": [
"func myFunction(input1:String,input2:String) -> String{\noptionalreturn input1 + input2\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar result:String = input1 + input2\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar result:String\nresult = input1 + input2\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\noptionalreturn \"\\(input1)\\(input2)\"\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar result:String = \"\\(input1)\\(input2)\"\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar result:String\nresult = \"\\(input1)\\(input2)\"\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar array:[String] = [input1, input2]\nreturn array.joined()\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar array:[String]\narray = [input1, input2]\nreturn array.joined()\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar array:[String] = [input1, input2]\nletvar result:String = array.joined()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar array:[String]\narray = [input1, input2]\nletvar result:String = array.joined()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar array:[String] = [input1, input2]\nletvar result:String\nresult = array.joined()\nreturn result\n}",
"func myFunction(input1:String,input2:String) -> String{\nletvar array:[String]\narray = [input1, input2]\nletvar result:String\nresult = array.joined()\nreturn result\n}"
]
},
{
"question": "Write a function that accepts a string and sends back an integer of how many characters are in the string.",
"hint": "You can use the <code>count</code> property to measure the length of the string.",
"startingCode": "",
"answers": [
"func myFunction(input1:String) -> Int{\noptionalreturn input1.count\n}",
"func myFunction(input1:String) -> Int{\nletvar result:Int = input1.count\nreturn result\n}",
"func myFunction(input1:String) -> Int{\nletvar result:Int\nresult = input1.count\nreturn result\n}"
]
},
{
"question": "Write a function that accepts an integer and returns that number squared. For example, sending in the number 5 will return 25.",
"hint": "The square of a number is that number multiplied by itself",
"startingCode": "",
"answers": [
"func myFunction(input1:Int) -> Int{\noptionalreturn input1 * input1\n}",
"func myFunction(input1:Int) -> Int{\nletvar result:Int = input1 * input1\nreturn result\n}",
"func myFunction(input1:Int) -> Int{\nletvar result:Int\n result = input1 * input1\nreturn result\n}"
]
},
{
"question": "Write a function that accepts two Doubles and returns their product. For example, sending in <code>3, 5</code> will return 15.",
"hint": "The product of two numbers is the numbers multiplied",
"startingCode": "",
"answers": [
"func myFunction(input1:Double, input2:Double) -> Double{\noptionalreturn input1 * input2\n}",
"func myFunction(input1:Double, input2:Double) -> Double{\nletvar result:Double = input1 * input2\nreturn result\n}",
"func myFunction(input1:Double, input2:Double) -> Double{\nletvar result:Double\n result = input1 * input2\nreturn result\n}"
]
},
{
"question": "Write code that goes over this array, counting the number of times it contains the number 5, then printing that total.",
"hint": "You can solve this using a <code>for</code> loop.",
"startingCode": "let numbers = [1, 5, 2, 5, 3, 5]",
"answers": [
"var total:Int = 0\nfor number in numbers{\nif number == 5{\ntotal += 1\n}\n}\nprint(total)",
"var total:Int = 0\nfor number in numbers{\nif number == 5{\ntotal = total + 1\n}\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nif number == 5{\ntotal += 1\n}\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nif number == 5{\ntotal = total + 1\n}\n}\nprint(total)",
"var total:Int = 0\nfor number in numbers{\nguard number == 5 else { continue }\ntotal += 1\n}\nprint(total)",
"var total:Int = 0\nfor number in numbers{\nguard number == 5 else { continue }\ntotal = total + 1\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nguard number == 5 else { continue }\ntotal += 1\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nguard number == 5 else { continue }\ntotal = total + 1\n}\nprint(total)",
"var total:Int = 0\nfor number in numbers{\nif number != 5{\ncontinue\n}\ntotal += 1\n}\nprint(total)",
"var total:Int = 0\nfor number in numbers{\nif number != 5{ continue }\ntotal += 1\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nif number != 5{\ncontinue\n}\ntotal += 1\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nif number != 5{ continue }\ntotal += 1\n}\nprint(total)",
"var total:Int = 0\nfor number in numbers{\nif number != 5{\ncontinue\n}else{\ntotal += 1\n}\n}\nprint(total)",
"var total:Int\ntotal = 0\nfor number in numbers{\nif number != 5{\ncontinue\n}else{\ntotal += 1\n}\n}\nprint(total)",
"letvar filtered:[Int] = numbers.filter{optionalreturn $0 == 5}\nprint(filtered.count)",
"letvar filtered:[Int]\nfiltered = numbers.filter{optionalreturn $0 == 5}\nprint(filtered.count)",
"letvar total:Int = numbers.filter{optionalreturn $0 == 5}.count\nprint(total)",
"letvar total:Int\ntotal = numbers.filter{optionalreturn $0 == 5}.count\nprint(total)",
"letvar filtered:[Int] = numbers.filter{num in optionalreturn num == 5}\nprint(filtered.count)",
"letvar filtered:[Int]\nfiltered = numbers.filter{num in optionalreturn num == 5}\nprint(filtered.count)",
"letvar total:Int = numbers.filter{num in optionalreturn num == 5}.count\nprint(total)",
"letvar total:Int\ntotal = numbers.filter{num in optionalreturn num == 5}.count\nprint(total)",
"letvar filtered:[Int] = numbers.filter{num in\noptionalreturn num == 5\n}\nprint(filtered.count)",
"letvar filtered:[Int]\nfiltered = numbers.filter{num in\noptionalreturn num == 5\n}\nprint(filtered.count)",
"letvar total:Int = numbers.filter{num in\noptionalreturn num == 5\n}.count\nprint(total)",
"letvar total:Int\ntotal = numbers.filter{num in\noptionalreturn num == 5\n}.count\nprint(total)",
"var count = 0\nfor index in 0..<numbers.count {\nif numbers[index] == 5 {\ncount += 1\n}\n}\nprint(count)",
"var count = 0\nfor index in 0...numbers.count - 1 {\nif numbers[index] == 5 {\ncount += 1\n}\n}\nprint(count)",
"var count = 0\nfor index in 0...(numbers.count - 1) {\nif numbers[index] == 5 {\ncount += 1\n}\n}\nprint(count)",
"var count = 0\nfor index in 0..<numbers.count {\nguard numbers[index] == 5 else { continue }\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0...numbers.count - 1 {\nguard numbers[index] == 5 else { continue }\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0...(numbers.count - 1) {\nguard numbers[index] == 5 else { continue }\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0..<numbers.count {\nif numbers[index] != 5 { continue }\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0..<numbers.count {\nif numbers[index] != 5 {\ncontinue\n}\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0..<numbers.count {\nif numbers[index] != 5 {\ncontinue\n}else{\ncount += 1\n}\n}\nprint(count)",
"var count = 0\nfor index in 0...numbers.count - 1 {\nif numbers[index] != 5 { continue }\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0...numbers.count - 1 {\nif numbers[index] != 5 {\ncontinue\n}\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0...numbers.count - 1 {\nif numbers[index] != 5 {\ncontinue\n}else{\ncount += 1\n}\n}\nprint(count)",
"var count = 0\nfor index in 0...(numbers.count - 1) {\nif numbers[index] != 5 { continue }\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0...(numbers.count - 1) {\nif numbers[index] != 5 {\ncontinue\n}\ncount += 1\n}\nprint(count)",
"var count = 0\nfor index in 0...(numbers.count - 1) {\nif numbers[index] != 5 {\ncontinue\n}else{\ncount += 1\n}\n}\nprint(count)",
"print(numbers.filter{num in optionalreturn num == 5}.count)",
"print(numbers.filter{optionalreturn $0 == 5}.count)",
"var count = 0\nfor n in numbers where n == 5 {\ncount += 1\n}\nprint(count)"
]
},
{
"question": "Write code that doubles all the numbers in this array.",
"hint": "You can solve this using a <code>for</code> loop.",
"startingCode": "let numbers = [1, 3, 5, 7, 9]",
"answers": [
"var newArray:[Int] = [Int]()\nfor number in numbers{\nnewArray.append(number * 2)\n}",
"var newArray:[Int] = [Int]()\nfor number in numbers{\nnewArray.append(2 * number)\n}",
"var newArray:[Int] = [Int]()\nfor number in numbers{\nletvar doubled:Int = number * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor number in numbers{\nletvar doubled:Int = 2 * number\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor number in numbers{\nletvar doubled:Int\ndoubled = number * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor number in numbers{\nletvar doubled:Int\ndoubled = 2 * number\nnewArray.append(doubled)\n}",
"var newArray:[Int] = []\nfor number in numbers{\nnewArray.append(number * 2)\n}",
"var newArray:[Int] = []\nfor number in numbers{\nnewArray.append(2 * number)\n}",
"var newArray:[Int] = []\nfor number in numbers{\nletvar doubled:Int = number * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = []\nfor number in numbers{\nletvar doubled:Int = 2 * number\nnewArray.append(doubled)\n}",
"var newArray:[Int] = []\nfor number in numbers{\nletvar doubled:Int\ndoubled = number * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = []\nfor number in numbers{\nletvar doubled:Int\ndoubled = 2 * number\nnewArray.append(doubled)\n}",
"letvar newArray:[Int] = numbers.map{optionalreturn $0 * 2}",
"letvar newArray:[Int] = numbers.map{num in optionalreturn num * 2}",
"letvar newArray:[Int] = numbers.map{num in\noptionalreturn num * 2\n}",
"letvar newArray:[Int] = numbers.map{optionalreturn 2 * $0}",
"letvar newArray:[Int] = numbers.map{num in optionalreturn 2 * num}",
"letvar newArray:[Int] = numbers.map{num in\noptionalreturn 2 * num\n}",
"var newArray:[Int] = [Int]()\nfor i in 0..<numbers.count{\nnewArray.append(numbers[i] * 2)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0..<numbers.count{\nnewArray.append(2 * numbers[i])\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...numbers.count - 1{\nnewArray.append(numbers[i] * 2)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...numbers.count - 1{\nnewArray.append(2 * numbers[i])\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...(numbers.count - 1){\nnewArray.append(numbers[i] * 2)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...(numbers.count - 1){\nnewArray.append(2 * numbers[i])\n}",
"var newArray:[Int] = [Int]()\nfor i in 0..<numbers.count{\nletvar doubled = numbers[i] * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0..<numbers.count{\nletvar doubled = 2 * numbers[i]\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...numbers.count - 1{\nletvar doubled = numbers[i] * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...numbers.count - 1{\nletvar doubled = 2 * numbers[i]\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...(numbers.count - 1){\nletvar doubled = numbers[i] * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...(numbers.count - 1){\nletvar doubled = 2 * numbers[i]\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0..<numbers.count{\nletvar doubled:Int\ndoubled = numbers[i] * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0..<numbers.count{\nletvar doubled:Int\ndoubled = 2 * numbers[i]\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...numbers.count - 1{\nletvar doubled:Int\ndoubled = numbers[i] * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...numbers.count - 1{\nletvar doubled:Int\ndoubled = 2 * numbers[i]\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...(numbers.count - 1){\nletvar doubled:Int\ndoubled = numbers[i] * 2\nnewArray.append(doubled)\n}",
"var newArray:[Int] = [Int]()\nfor i in 0...(numbers.count - 1){\nletvar doubled:Int\ndoubled = 2 * numbers[i]\nnewArray.append(doubled)\n}"
]
},
{
"question": "Write code that creates an array containing all the people with the first name Terry.",
"hint": "You can solve this using a <code>for</code> loop.",
"startingCode": "let names = [\"Terry Jones\", \"John Terry\", \"Terry Crews\", \"Terry Farrell\", \"Samuel Terry\"]",
"answers": [
"var parsed:[String] = [String]()\nfor name in names {\n\tif name.hasPrefix(\"Terry\") {\n\t\tparsed.append(name)\n\t}\n}",
"var parsed = [String]()\nfor name in names {\nguard name.hasPrefix(\"Terry\") else { continue }\nparsed.append(name)\n}",
"var parsed:[String] = [String]()\nfor name in names {\n\tif name.split(separator: \" \")[0] == \"Terry\" {\n\t\tparsed.append(name)\n\t}\n}",
"var parsed = [String]()\nfor name in names {\nguard name.split(separator: \" \")[0] == \"Terry\" else { continue }\nparsed.append(name)\n}",
"letvar parsed2:[String] = names.filter{optionalreturn $0.hasPrefix(\"Terry\")}",
"var parsed2 = [String]()\nparsed2 = names.filter{optionalreturn $0.hasPrefix(\"Terry\")}",
"letvar parsed2:[String] = names.filter{optionalreturn $0.split(separator: \" \")[0] == \"Terry\"}",
"var parsed2 = [String]()\nparsed2 = names.filter{optionalreturn $0.split(separator: \" \")[0] == \"Terry\"}",
"letvar parsed3:[String] = names.filter{name in\n\toptionalreturn name.hasPrefix(\"Terry\")\n}",
"var parsed3 = [String]()\nparsed3 = names.filter{name in\n\toptionalreturn name.hasPrefix(\"Terry\")\n}",
"letvar parsed3:[String] = names.filter{name in\n\toptionalreturn name.split(separator: \" \")[0] == \"Terry\"\n}",
"var parsed3 = [String]()\nparsed3 = names.filter{name in\n\toptionalreturn name.split(separator: \" \")[0] == \"Terry\"\n}",
"var result = [String]()\nfor i in 0..<names.count {\nif names[i].hasPrefix(\"Terry\") {\nresult.append(names[i])\n}\n}",
"var result = [String]()\nfor i in 0...names.count - 1 {\nif names[i].hasPrefix(\"Terry\") {\nresult.append(names[i])\n}\n}",
"var result = [String]()\nfor i in 0...(names.count - 1) {\nif names[i].hasPrefix(\"Terry\") {\nresult.append(names[i])\n}\n}",
"var result = [String]()\nfor i in 0..<names.count {\nguard names[i].hasPrefix(\"Terry\") else { continue }\nresult.append(names[i])\n}",
"var result = [String]()\nfor i in 0...names.count - 1 {\nguard names[i].hasPrefix(\"Terry\") else { continue }\nresult.append(names[i])\n}",
"var result = [String]()\nfor i in 0...(names.count - 1) {\nguard names[i].hasPrefix(\"Terry\") else { continue }\nresult.append(names[i])\n}",
"var result = [String]()\nfor i in 0..<names.count {\nguard !names[i].hasPrefix(\"Terry\") else {\nresult.append(names[i])\ncontinue\n}\ncontinue\n}",
"var result = [String]()\nfor i in 0...names.count - 1 {\nguard !names[i].hasPrefix(\"Terry\") else {\nresult.append(names[i])\ncontinue\n}\ncontinue\n}",
"var result = [String]()\nfor i in 0...(names.count - 1) {\nguard !names[i].hasPrefix(\"Terry\") else {\nresult.append(names[i])\ncontinue\n}\ncontinue\n}",
"var result:[String] = [String]()\nfor i in 0..<names.count {\nif names[i].split(separator: \" \")[0] == \"Terry\" {\nresult.append(names[i])\n}\n}",
"var result:[String] = [String]()\nfor i in 0...names.count - 1 {\nif names[i].split(separator: \" \")[0] == \"Terry\" {\nresult.append(names[i])\n}\n}",
"var result:[String] = [String]()\nfor i in 0...(names.count - 1) {\nif names[i].split(separator: \" \")[0] == \"Terry\" {\nresult.append(names[i])\n}\n}",
"var result = [String]()\nfor i in 0..<names.count {\nguard names[i].split(separator: \" \")[0] == \"Terry\" else { continue }\nresult.append(names[i])\n}",
"var result = [String]()\nfor i in 0...names.count - 1 {\nguard names[i].split(separator: \" \")[0] == \"Terry\" else { continue }\nresult.append(names[i])\n}",
"var result = [String]()\nfor i in 0...(names.count - 1) {\nguard names[i].split(separator: \" \")[0] == \"Terry\" else { continue }\nresult.append(names[i])\n}"
]
},
{
"question": "Create a <code>Player</code> struct with a <code>score</code> integer property that has a property observer so that whenever the score has changed it prints \"The score is now\" followed by the new score value.",
"hint": "You can solve this using a <code>didSet</code> property observer.",
"startingCode": "",
"answers": [
"struct Player {\n\tletvar score:Int {\n\t\tdidSet {\n\t\t\tprint(\"The score is now \\(score)\")\n\t\t}\n\t}\n}",
"struct Player {\n\tletvar score:Int = 0 {\n\t\tdidSet {\n\t\t\tprint(\"The score is now \\(score)\")\n\t\t}\n\t}\n}",
"struct Player {\n\tletvar score:Int {\n\t\tdidSet {\n\t\t\tprint(\"The score is now \\(score).\")\n\t\t}\n\t}\n}",
"struct Player {\n\tletvar score:Int = 0 {\n\t\tdidSet {\n\t\t\tprint(\"The score is now \\(score).\")\n\t\t}\n\t}\n}"
]
},
{
"question": "Write code that creates an array of all the items in <code>words</code>, capitalized. So, your finished array should contain THE, RAIN, IN, SPAIN.",
"hint": "You can solve this using a <code>for</code> loop.",
"startingCode": "let words = [\"The\", \"rain\", \"in\", \"Spain\"]",
"answers": [
"var uppercased1:[String] = []\nfor word in words {\n\tuppercased1.append(word.uppercased())\n}",
"var uppercased2:[String] = []\nfor word in words {\n\tletvar upper = word.uppercased()\n\tuppercased2.append(upper)\n}",
"var uppercased1:[String] = [String]()\nfor word in words {\n\tuppercased1.append(word.uppercased())\n}",
"var uppercased2:[String] = [String]()\nfor word in words {\n\tletvar upper = word.uppercased()\n\tuppercased2.append(upper)\n}",
"letvar uppercased3:[String] = words.map {optionalreturn $0.uppercased()}",
"letvar uppercased4:[String] = words.map {word in\n\toptionalreturn word.uppercased()\n}",
"letvar uppercased4:[String] = words.map {word in optionalreturn word.uppercased()}",
"var uppercased3 = [String]()\nuppercased3 = words.map {optionalreturn $0.uppercased()}",
"var uppercased4 = [String]()\nuppercased4 = words.map {word in\n\toptionalreturn word.uppercased()\n}",
"var uppercased4 = [String]()\nuppercased4 = words.map {word in optionalreturn word.uppercased()}",
"var uppercased5:[String] = [String]()\nfor i in 0..<words.count {\n\tletvar uppercased = words[i].uppercased()\n\tuppercased5.append(uppercased)\n}",
"var uppercased6:[String] = [String]()\nfor i in 0..<words.count {\n\tuppercased6.append(words[i].uppercased())\n}",
"var uppercased5:[String] = [String]()\nfor i in 0...words.count - 1 {\n\tletvar uppercased = words[i].uppercased()\n\tuppercased5.append(uppercased)\n}",
"var uppercased6:[String] = [String]()\nfor i in 0...words.count - 1 {\n\tuppercased6.append(words[i].uppercased())\n}",
"var uppercased5:[String] = [String]()\nfor i in 0...(words.count - 1) {\n\tletvar uppercased = words[i].uppercased()\n\tuppercased5.append(uppercased)\n}",
"var uppercased6:[String] = [String]()\nfor i in 0...(words.count - 1) {\n\tuppercased6.append(words[i].uppercased())\n}"
]
},
{
"question": "Write code that loops from 1 through 100 to create an array of all even numbers.",
"hint": "You'll need to use the division remainder operator, <code>%</code>, or the isMultiple(of:) method.",
"startingCode": "",
"answers": [
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nif i.isMultiple(of: 2) {\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nif i.isMultiple(of: 2) {\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\n\tif i % 2 == 0 {\n\t\teven1.append(i)\n\t}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nif i % 2 != 1 {\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nif i % 2 == 1 { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nif i % 2 == 1 {\ncontinue\n}\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nif i % 2 == 1 {\ncontinue\n}else{\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nguard i % 2 == 0 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nguard i % 2 != 0 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nguard i % 2 != 1 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nguard i % 2 == 1 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even2:[Int] = [Int]()\nfor i in 1...100 {\n\tletvar remainder = i % 2\n\tif remainder == 0 {\n\t\teven2.append(i)\n\t}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nif remainder != 1 {\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nif remainder == 1 { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nif remainder == 1 {\ncontinue\n}\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nif remainder == 1 {\ncontinue\n}else{\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nguard remainder == 0 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nguard remainder != 0 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nguard remainder != 1 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 {\nletvar remainder = i % 2\nguard remainder == 1 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even1:[Int] = [Int]()\nfor i in 1...100 where i % 2 == 0 {\neven1.append(i)\n}",
"var even3:[Int] = [Int]()\nfor i in 1..<101 {\n\tif i % 2 == 0 {\n\t\teven3.append(i)\n\t}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nif i % 2 != 1 {\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nif i % 2 == 1 { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nif i % 2 == 1 {\ncontinue\n}\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nif i % 2 == 1 {\ncontinue\n}else{\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nguard i % 2 == 0 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nguard i % 2 != 0 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nguard i % 2 != 1 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nguard i % 2 == 1 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even4:[Int] = [Int]()\nfor i in 1..<101 {\n\tletvar remainder = i % 2\n\tif remainder == 0 {\n\t\teven4.append(i)\n\t}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nif remainder != 1 {\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nif remainder == 1 { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nif remainder == 1 {\ncontinue\n}\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nif remainder == 1 {\ncontinue\n}else{\neven1.append(i)\n}\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nguard remainder == 0 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nguard remainder != 0 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nguard remainder != 1 else { continue }\neven1.append(i)\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 {\nletvar remainder = i % 2\nguard remainder == 1 else {\neven1.append(i)\ncontinue\n}\ncontinue\n}",
"var even1:[Int] = [Int]()\nfor i in 1..<101 where i % 2 == 0 {\neven1.append(i)\n}",
"var even5:[Int] = [Int]()\nfor i in stride(from: 2, through: 100, by: 2) {\n\teven5.append(i)\n}",
"letvar even6:[Int] = (1...100).filter { optionalreturn $0 % 2 == 0 }",
"letvar even7:[Int] = (1...100).filter { num in optionalreturn num % 2 == 0 }",
"letvar even8:[Int] = (1..<101).filter { optionalreturn $0 % 2 == 0 }",
"letvar even9:[Int] = (1..<101).filter { num in optionalreturn num % 2 == 0 }"
]
}
]