Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions exercises/flatten-array/canonical-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@
3
]
},
{
"uuid": "bc72da10-5f55-4ada-baf3-50e4da02ec8e",
"reimplements": "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc",
"description": "consecutive null values at the front of the array are omitted from the final result",
"comments": ["Replaces references to lists with arrays in description."],
"property": "flatten",
"input": {
"array": [
null,
null,
3
]
},
"expected": [
3
]
},
{
"uuid": "382c5242-587e-4577-b8ce-a5fb51e385a1",
"description": "consecutive null values in the middle of the list are omitted from the final result",
Expand All @@ -200,6 +217,25 @@
4
]
},
{
"uuid": "6991836d-0d9b-4703-80a0-3f1f23eb5981",
"reimplements": "382c5242-587e-4577-b8ce-a5fb51e385a1",
"description": "consecutive null values in the middle of the array are omitted from the final result",
"comments": ["Replaces references to lists with arrays in description."],
"property": "flatten",
"input": {
"array": [
1,
null,
null,
4
]
},
"expected": [
1,
4
]
},
{
"uuid": "ef1d4790-1b1e-4939-a179-51ace0829dbd",
"description": "6 level nest list with null values",
Expand Down Expand Up @@ -239,6 +275,47 @@
-2
]
},
{
"uuid": "dc90a09c-5376-449c-a7b3-c2d20d540069",
"reimplements": "ef1d4790-1b1e-4939-a179-51ace0829dbd",
"description": "6 level nested array with null values",
"comments": ["Replaces references to lists with arrays in description."],
"property": "flatten",
"input": {
"array": [
0,
2,
[
[
2,
3
],
8,
[
[
100
]
],
null,
[
[
null
]
]
],
-2
]
},
"expected": [
0,
2,
2,
3,
8,
100,
-2
]
},
{
"uuid": "85721643-705a-4150-93ab-7ae398e2942d",
"description": "all values in nested list are null",
Expand Down Expand Up @@ -266,6 +343,36 @@
]
},
"expected": []
},
{
"uuid": "51f5d9af-8f7f-4fb5-a156-69e8282cb275",
"reimplements": "85721643-705a-4150-93ab-7ae398e2942d",
"description": "all values in nested array are null",
"comments": ["Replaces references to lists with arrays in description."],
"property": "flatten",
"input": {
"array": [
null,
[
[
[
null
]
]
],
null,
null,
[
[
null,
null
],
null
],
null
]
},
"expected": []
}
]
}
15 changes: 10 additions & 5 deletions exercises/flatten-array/description.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Description

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

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

For example:
Additionally, input arrays may have data of different types, depending on the track.

input: [1,[2,3,null,4],[null],5]
Check the test suite for details.

output: [1,2,3,4,5]
## Example

input: `[1,[2,6,null],[[null,[4]],5]]`

output: `[1,2,6,4,5]`
Loading