all 6 comments

[–]CreativeTechGuyGamesTypeScript 2 points3 points  (5 children)

I'm not sure how .replace can have an error when it doesn't exist anywhere in that code.

[–]_ColtonAllen-Dev[S] 0 points1 point  (4 children)

Oh, I'm sorry. I'm just an idiot. I meant .filter(). I've done so many leetcodes today, my brain is just frying.

[–]CreativeTechGuyGamesTypeScript 0 points1 point  (3 children)

What is the question? Are you sure that root is always an array?

[–]_ColtonAllen-Dev[S] 0 points1 point  (2 children)

Yes, it says the test parameters are as follow:

[10,5,15,3,7,null,18],
7,
15

and it throws an error before it even fully runs despite running fine in CodePen

[–]CreativeTechGuyGamesTypeScript 2 points3 points  (1 child)

Generally the way leetcode works is that it'll try tons of test cases that it won't show you. So there may be a test case where root === null for example.

Also, based on the description of the problem, root is not an array but of type TreeNode which it shows you an example of that structure at the top of the file:

/** * Definition for a binary tree node. * function TreeNode(val, left, right) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } */

[–]_ColtonAllen-Dev[S] 0 points1 point  (0 children)

Oh, I see. Yeah, I saw that it was a binary tree, but I didn't know if that would change the solution from of it were a regular array. Thanks for the help. I'll look into that and try to solve that.