We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f61447c commit 622b682Copy full SHA for 622b682
1 file changed
src/utilities/content-utils.mjs
@@ -21,16 +21,24 @@ export const walkContent = (tree, callback) => {
21
* @return {array} - A flattened list of leaf node descendants
22
*/
23
export const flattenContent = (tree) => {
24
- if (tree.children) {
25
- return tree.children.reduce(
26
- (flat, item) => [
27
- ...flat,
28
- ...(Array.isArray(item.children) ? flattenContent(item) : [item]),
29
- ],
30
- [],
31
- );
+ const flat = [];
+ const walk = (node) => {
+ if (node && Array.isArray(node.children)) {
+ for (const child of node.children) {
+ walk(child);
+ }
+ } else {
+ flat.push(node);
32
33
+ };
34
+
35
+ if (tree && Array.isArray(tree.children)) {
36
+ for (const child of tree.children) {
37
38
39
}
- return [];
40
41
+ return flat;
42
};
43
44
/**
0 commit comments