-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path04_flat.org
More file actions
22 lines (17 loc) · 1011 Bytes
/
Copy path04_flat.org
File metadata and controls
22 lines (17 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
* flatten
Implement =flatten=, a function that removes (flattens out) nested structure.
Examples:
: [1, 2, [3, 4]] --> [1, 2, 3, 4]
: [[1, 2], [3, 4]] --> [1, 2, 3, 4]
Use any language and data structure/representation that makes sense. Go for the basic behavior first, but see bonus implementation notes for ideas.
** Bonus implementation ideas:
These are of varying difficulty. Depending on your experience/skill, try some of these variants.
1. Handle arbitrarily deep nesting (e.g. =[[[[1], [2, 3]]]] -> [1, 2, 3]=)
2. Allow an extra argument that sets the number of levels to flatten
3. Support any combination of iterables as input
4. Implement a unit test suite
5. Write a version with no loop constructs
6. Write a version in a pure functional style
7. Write a version with no recursive calls
8. Write a version you'd deploy into production. Explain your choices for the production version.
9. Implement a property-based testing suite (using e.g. jsverify)