Skip to content

Commit 680cba3

Browse files
committed
May have a solution. Commiting before testing and iterating.
1 parent 3a37272 commit 680cba3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/parser.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class Parser {
5858
this.tree = root;
5959
this.parser(root);
6060
// clean up nodes with error: 'File not found'
61-
61+
this.cleanUp(this.tree);
6262
return this.tree;
6363
}
6464

@@ -73,15 +73,20 @@ export class Parser {
7373
*/
7474
private cleanUp(tree: Tree): void {
7575
// base case
76-
76+
if(tree.children.length === 0) return;
7777
// iterate over tree.children array to check for error. I will have to check the children array of
7878
// the elements in this loop and recursively call cleanUp on it
79+
// but how can i modify the children array, since im iterating over it.
80+
//
7981
for(let i = 0; i < tree.children.length; i++){
8082
if(tree.children[i].children.length !== 0){
8183
this.cleanUp(tree.children[i]);
8284
}
8385
if(tree.children[i].error && tree.children[i].error === 'File not found'){
84-
tree.children
86+
// when I find an element with the error, i need to slice it from the children array
87+
// how can i do this without modifying the array that i'm iterating over?
88+
tree.children.splice(i,1);
89+
i--;
8590
}
8691
}
8792
};

0 commit comments

Comments
 (0)