Skip to content

Commit c30d44e

Browse files
tasxatzialIsaacG
andauthored
flatten-array: Replace references to lists with arrays, and revise instructions (#2533)
* revise instructions * replace references to lists with arrays in test descriptions * Apply suggestions from code review Co-authored-by: Isaac Good <[email protected]> --------- Co-authored-by: Isaac Good <[email protected]>
1 parent 48f11be commit c30d44e

File tree

2 files changed

+117
-5
lines changed

2 files changed

+117
-5
lines changed

exercises/flatten-array/canonical-data.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@
183183
3
184184
]
185185
},
186+
{
187+
"uuid": "bc72da10-5f55-4ada-baf3-50e4da02ec8e",
188+
"reimplements": "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc",
189+
"description": "consecutive null values at the front of the array are omitted from the final result",
190+
"comments": ["Replaces references to lists with arrays in description."],
191+
"property": "flatten",
192+
"input": {
193+
"array": [
194+
null,
195+
null,
196+
3
197+
]
198+
},
199+
"expected": [
200+
3
201+
]
202+
},
186203
{
187204
"uuid": "382c5242-587e-4577-b8ce-a5fb51e385a1",
188205
"description": "consecutive null values in the middle of the list are omitted from the final result",
@@ -200,6 +217,25 @@
200217
4
201218
]
202219
},
220+
{
221+
"uuid": "6991836d-0d9b-4703-80a0-3f1f23eb5981",
222+
"reimplements": "382c5242-587e-4577-b8ce-a5fb51e385a1",
223+
"description": "consecutive null values in the middle of the array are omitted from the final result",
224+
"comments": ["Replaces references to lists with arrays in description."],
225+
"property": "flatten",
226+
"input": {
227+
"array": [
228+
1,
229+
null,
230+
null,
231+
4
232+
]
233+
},
234+
"expected": [
235+
1,
236+
4
237+
]
238+
},
203239
{
204240
"uuid": "ef1d4790-1b1e-4939-a179-51ace0829dbd",
205241
"description": "6 level nest list with null values",
@@ -239,6 +275,47 @@
239275
-2
240276
]
241277
},
278+
{
279+
"uuid": "dc90a09c-5376-449c-a7b3-c2d20d540069",
280+
"reimplements": "ef1d4790-1b1e-4939-a179-51ace0829dbd",
281+
"description": "6 level nested array with null values",
282+
"comments": ["Replaces references to lists with arrays in description."],
283+
"property": "flatten",
284+
"input": {
285+
"array": [
286+
0,
287+
2,
288+
[
289+
[
290+
2,
291+
3
292+
],
293+
8,
294+
[
295+
[
296+
100
297+
]
298+
],
299+
null,
300+
[
301+
[
302+
null
303+
]
304+
]
305+
],
306+
-2
307+
]
308+
},
309+
"expected": [
310+
0,
311+
2,
312+
2,
313+
3,
314+
8,
315+
100,
316+
-2
317+
]
318+
},
242319
{
243320
"uuid": "85721643-705a-4150-93ab-7ae398e2942d",
244321
"description": "all values in nested list are null",
@@ -266,6 +343,36 @@
266343
]
267344
},
268345
"expected": []
346+
},
347+
{
348+
"uuid": "51f5d9af-8f7f-4fb5-a156-69e8282cb275",
349+
"reimplements": "85721643-705a-4150-93ab-7ae398e2942d",
350+
"description": "all values in nested array are null",
351+
"comments": ["Replaces references to lists with arrays in description."],
352+
"property": "flatten",
353+
"input": {
354+
"array": [
355+
null,
356+
[
357+
[
358+
[
359+
null
360+
]
361+
]
362+
],
363+
null,
364+
null,
365+
[
366+
[
367+
null,
368+
null
369+
],
370+
null
371+
],
372+
null
373+
]
374+
},
375+
"expected": []
269376
}
270377
]
271378
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Description
22

3-
Take a nested list and return a single flattened list with all values except nil/null.
3+
Take a nested array of any depth and return a fully flattened array.
44

5-
The challenge is to take an arbitrarily-deep nested list-like structure and produce a flattened structure without any nil/null values.
5+
Note that some language tracks may include null-like values in the input array, and the way these values are represented varies by track.
6+
Such values should be excluded from the flattened array.
67

7-
For example:
8+
Additionally, the input may be of a different data type and contain different types, depending on the track.
89

9-
input: [1,[2,3,null,4],[null],5]
10+
Check the test suite for details.
1011

11-
output: [1,2,3,4,5]
12+
## Example
13+
14+
input: `[1, [2, 6, null], [[null, [4]], 5]]`
15+
16+
output: `[1, 2, 6, 4, 5]`

0 commit comments

Comments
 (0)