Skip to content

Commit 5e96674

Browse files
authored
Sync Flatten-Array (#2928)
This change also adds an instructions.append.md since the instructions have been updated to refer to "arrays" instead of "lists" and we want to avoid updating the exercises for now (which would invalidate existing solutions).
1 parent 6c4a0b3 commit 5e96674

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Instructions append
2+
3+
For the Java track, the input will be provided as a `List` instead of an array, and the output should also be a `List`.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Instructions
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]`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
A shipment of emergency supplies has arrived, but there's a problem.
4+
To protect from damage, the items — flashlights, first-aid kits, blankets — are packed inside boxes, and some of those boxes are nested several layers deep inside other boxes!
5+
6+
To be prepared for an emergency, everything must be easily accessible in one box.
7+
Can you unpack all the supplies and place them into a single box, so they're ready when needed most?

exercises/practice/flatten-array/.meta/tests.toml

+20
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,32 @@ description = "null values are omitted from the final result"
3232

3333
[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
3434
description = "consecutive null values at the front of the list are omitted from the final result"
35+
include = false
36+
37+
[bc72da10-5f55-4ada-baf3-50e4da02ec8e]
38+
description = "consecutive null values at the front of the array are omitted from the final result"
39+
reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc"
3540

3641
[382c5242-587e-4577-b8ce-a5fb51e385a1]
3742
description = "consecutive null values in the middle of the list are omitted from the final result"
43+
include = false
44+
45+
[6991836d-0d9b-4703-80a0-3f1f23eb5981]
46+
description = "consecutive null values in the middle of the array are omitted from the final result"
47+
reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1"
3848

3949
[ef1d4790-1b1e-4939-a179-51ace0829dbd]
4050
description = "6 level nest list with null values"
51+
include = false
52+
53+
[dc90a09c-5376-449c-a7b3-c2d20d540069]
54+
description = "6 level nested array with null values"
55+
reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd"
4156

4257
[85721643-705a-4150-93ab-7ae398e2942d]
4358
description = "all values in nested list are null"
59+
include = false
60+
61+
[51f5d9af-8f7f-4fb5-a156-69e8282cb275]
62+
description = "all values in nested array are null"
63+
reimplements = "85721643-705a-4150-93ab-7ae398e2942d"

0 commit comments

Comments
 (0)