1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00
dotSCAD/docs/lib3x-flat.md

37 lines
756 B
Markdown
Raw Normal View History

2020-03-31 07:35:10 +08:00
# 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.
2021-02-10 14:53:04 +08:00
- `depth` : Default to 1. The depth level specifying how deep a nested list should be flattened.
2020-03-31 07:35:10 +08:00
## Examples
2022-06-06 13:11:46 +08:00
use <util/flat.scad>
2020-03-31 07:35:10 +08:00
vt = [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]];
assert(
2022-04-06 17:44:11 +08:00
flat([1, 2, [3, 4]]) == [1, 2, 3, 4]
2020-03-31 07:35:10 +08:00
);
assert(
2022-04-06 17:44:11 +08:00
flat([[1, 2], [3, 4]]) == [1, 2, 3, 4]
2020-03-31 07:35:10 +08:00
);
assert(
2022-04-06 17:44:11 +08:00
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) == [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
2020-03-31 07:35:10 +08:00
);
assert(
2022-04-06 17:44:11 +08:00
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 2) == [[1, 2], [3, 4], [5, 6], [7, 8]]
2020-03-31 07:35:10 +08:00
);
assert(
2022-04-06 17:44:11 +08:00
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 3) == [1, 2, 3, 4, 5, 6, 7, 8]
2020-03-31 07:35:10 +08:00
);