From dfecb557360c72f81dc44e3be39d5d17768b2bcb Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 31 Mar 2020 07:35:10 +0800 Subject: [PATCH] add doc --- docs/lib2x-flat.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docs/lib2x-flat.md diff --git a/docs/lib2x-flat.md b/docs/lib2x-flat.md new file mode 100644 index 00000000..ee73ebf8 --- /dev/null +++ b/docs/lib2x-flat.md @@ -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 ; + + 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] + );