Skip to content

Commit 3a37272

Browse files
Louis KuczykowskiLouis Kuczykowski
authored andcommitted
Working on a recursive function that iterates through the children of each tree and checks them for the File not found error string
1 parent 5696f60 commit 3a37272

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/parser.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,35 @@ export class Parser {
5757
};
5858
this.tree = root;
5959
this.parser(root);
60+
// clean up nodes with error: 'File not found'
61+
6062
return this.tree;
6163
}
6264

65+
/**
66+
* create some sort of recursive function that will check if the error in the tree is 'File not found'
67+
* how can i do this
68+
* well if im in the tree, i cant exactly take it out of the array because I'm already in it. So can i check
69+
* that error value when I'm one level out of it?
70+
* something like if(tree.children[i].error && tree.children[i].error === 'File not found') -> slice it out of the array
71+
* What would the base case be? When I'm out of elements in the children array? I think so
72+
*
73+
*/
74+
private cleanUp(tree: Tree): void {
75+
// base case
76+
77+
// iterate over tree.children array to check for error. I will have to check the children array of
78+
// the elements in this loop and recursively call cleanUp on it
79+
for(let i = 0; i < tree.children.length; i++){
80+
if(tree.children[i].children.length !== 0){
81+
this.cleanUp(tree.children[i]);
82+
}
83+
if(tree.children[i].error && tree.children[i].error === 'File not found'){
84+
tree.children
85+
}
86+
}
87+
};
88+
6389
public getTree(): Tree {
6490
return this.tree;
6591
}

0 commit comments

Comments
 (0)