mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
add doc
This commit is contained in:
41
docs/lib2x-flat.md
Normal file
41
docs/lib2x-flat.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# flat
|
||||||
|
|
||||||
|
returns a new list with all sub-list elements concatenated into it recursively up to the specified depth.
|
||||||
|
|
||||||
|
**Since:** 2.3
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `lt` : The original list.
|
||||||
|
- `depth` : Defaults to 1. The depth level specifying how deep a nested list should be flattened.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
use <util/flat.scad>;
|
||||||
|
|
||||||
|
vt = [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]];
|
||||||
|
|
||||||
|
assert(
|
||||||
|
flat([1, 2, [3, 4]]) ==
|
||||||
|
[1, 2, 3, 4]
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
flat([[1, 2], [3, 4]]) ==
|
||||||
|
[1, 2, 3, 4]
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) ==
|
||||||
|
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 2) ==
|
||||||
|
[[1, 2], [3, 4], [5, 6], [7, 8]]
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(
|
||||||
|
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 3) ==
|
||||||
|
[1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
|
);
|
Reference in New Issue
Block a user