Skip to content

Commit 58c21fa

Browse files
Sync flatten-array
1 parent dc57086 commit 58c21fa

5 files changed

Lines changed: 44 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Instructions append
2+
3+
## Elixir-specific changes
4+
5+
The above description of this exercise is shared between all Exercism tracks. It speaks of "arrays", but there is no such data type in Elixir. This exercise is about **lists**.
Lines changed: 10 additions & 5 deletions
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]`
Lines changed: 7 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,31 @@ description = "null values are omitted from the final result"
3333
[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
3434
description = "consecutive null values at the front of the list are omitted from the final result"
3535

36+
[bc72da10-5f55-4ada-baf3-50e4da02ec8e]
37+
description = "consecutive null values at the front of the array are omitted from the final result"
38+
reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc"
39+
include = false
40+
3641
[382c5242-587e-4577-b8ce-a5fb51e385a1]
3742
description = "consecutive null values in the middle of the list are omitted from the final result"
3843

44+
[6991836d-0d9b-4703-80a0-3f1f23eb5981]
45+
description = "consecutive null values in the middle of the array are omitted from the final result"
46+
reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1"
47+
include = false
48+
3949
[ef1d4790-1b1e-4939-a179-51ace0829dbd]
4050
description = "6 level nest list with null values"
4151

52+
[dc90a09c-5376-449c-a7b3-c2d20d540069]
53+
description = "6 level nested array with null values"
54+
reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd"
55+
include = false
56+
4257
[85721643-705a-4150-93ab-7ae398e2942d]
4358
description = "all values in nested list are null"
59+
60+
[51f5d9af-8f7f-4fb5-a156-69e8282cb275]
61+
description = "all values in nested array are null"
62+
reimplements = "85721643-705a-4150-93ab-7ae398e2942d"
63+
include = false

exercises/practice/flatten-array/test/flatten_array_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ defmodule FlattenArrayTest do
1414
end
1515

1616
@tag :pending
17-
test "flattens a nested array" do
17+
test "flattens a nested list" do
1818
assert FlattenArray.flatten([[[]]]) ==
1919
[]
2020
end
2121

2222
@tag :pending
23-
test "flattens array with just integers present" do
23+
test "flattens list with just integers present" do
2424
assert FlattenArray.flatten([1, [2, 3, 4, 5, 6, 7], 8]) ==
2525
[1, 2, 3, 4, 5, 6, 7, 8]
2626
end

0 commit comments

Comments
 (0)