Skip to content

Commit 70ceca3

Browse files
Sync flatten-array
1 parent f31cba5 commit 70ceca3

File tree

3 files changed

+65
-20
lines changed

3 files changed

+65
-20
lines changed
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]`

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"

exercises/practice/flatten-array/flatten-array-test.el

+35-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; flatten-array-test.el --- Flatten Array (exercism) -*- lexical-binding: t; -*-
1+
;;; flatten-array-test.el --- Tests for Flatten Array (exercism) -*- lexical-binding: t; -*-
22

33
;;; Commentary:
44

@@ -10,20 +10,31 @@
1010

1111

1212
(ert-deftest empty ()
13-
(should (equal (list-flatten '()) '())))
13+
(should
14+
(equal
15+
(list-flatten '())
16+
'())))
1417

1518

1619
(ert-deftest no-nesting ()
17-
(should (equal (list-flatten '(0 1 2)) '(0 1 2))))
20+
(should
21+
(equal
22+
(list-flatten '(0 1 2))
23+
'(0 1 2))))
1824

1925

2026
(ert-deftest flattens-a-nested-array ()
21-
(should (equal (list-flatten '((()))) '())))
27+
(should
28+
(equal
29+
(list-flatten '((())))
30+
'())))
2231

2332

2433
(ert-deftest flattens-array-with-just-integers-present ()
2534
(should
26-
(equal (list-flatten '(1 (2 3 4 5 6 7) 8)) '(1 2 3 4 5 6 7 8))))
35+
(equal
36+
(list-flatten '(1 (2 3 4 5 6 7) 8))
37+
'(1 2 3 4 5 6 7 8))))
2738

2839

2940
(ert-deftest 5-level-nesting ()
@@ -41,33 +52,42 @@
4152

4253

4354
(ert-deftest null-values-are-omitted-from-the-final-result ()
44-
(should (equal (list-flatten '(1 2 nil)) '(1 2))))
55+
(should
56+
(equal
57+
(list-flatten '(1 2 nil))
58+
'(1 2))))
4559

4660

4761
(ert-deftest
48-
consecutive-null-values-at-the-front-of-the-list-are-omitted-from-the-final-result
62+
consecutive-null-values-at-the-front-of-the-array-are-omitted-from-the-final-result
4963
()
50-
(should (equal (list-flatten '(nil nil 3)) '(3))))
64+
(should
65+
(equal
66+
(list-flatten '(nil nil 3))
67+
'(3))))
5168

5269

5370
(ert-deftest
54-
consecutive-null-values-in-the-middle-of-the-list-are-omitted-from-the-final-result
71+
consecutive-null-values-in-the-middle-of-the-array-are-omitted-from-the-final-result
5572
()
56-
(should (equal (list-flatten '(1 nil nil 4)) '(1 4))))
73+
(should
74+
(equal
75+
(list-flatten '(1 nil nil 4))
76+
'(1 4))))
5777

5878

59-
(ert-deftest 6-level-nest-list-with-null-values ()
79+
(ert-deftest 6-level-nested-array-with-null-values ()
6080
(should
6181
(equal
62-
(list-flatten
63-
'(0 2 ((2 3) 8 ((100)) nil ((nil))) -2))
82+
(list-flatten '(0 2 ((2 3) 8 ((100)) nil ((nil))) -2))
6483
'(0 2 2 3 8 100 -2))))
6584

6685

67-
(ert-deftest all-values-in-nested-list-are-null ()
86+
(ert-deftest all-values-in-nested-array-are-null ()
6887
(should
6988
(equal
70-
(list-flatten '(nil (((nil))) nil nil ((nil nil) nil) nil)) '())))
89+
(list-flatten '(nil (((nil))) nil nil ((nil nil) nil) nil))
90+
'())))
7191

7292

7393
(provide 'flatten-array-test)

0 commit comments

Comments
 (0)