Skip to content

Commit 36267f8

Browse files
committed
Add Comment
1 parent 8d1cea8 commit 36267f8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

flattenComponent.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
// functionality to flatten component tree data structure.
2+
13
function flattenComponent(components, flattened = []) {
2-
components.forEach((element,index) => {
4+
components.forEach((element, index) => {
35
let obj = {};
46
obj['title'] = element.title;
57
obj['children'] = element.children;
68
flattened.push(obj);
7-
flattenComponent(components[index].children,flattened);
9+
flattenComponent(components[index].children, flattened);
810
})
911
return flattened;
10-
}
11-
// console.log(flattenComponent([{title:'a',children:[{title:'b',children:[{title:'c',children:[]}]}]},{title:'d', children:[{title:'e',children:[]}]}]))
1212

13-
module.exports = flattenComponent;
13+
14+
module.exports = flattenComponent;
1415

1516

0 commit comments

Comments
 (0)