I have a file tree with this type
interface FileTreeProps {
name: string;
isMat?: boolean;
children?: FileTreeProps[];
}
After the user inputs and submits the query I want a filtered tree where the endpoints lead to the child having the type isMat. The first two children are parent folders and will never contain isMat = true. How do I go about filtering this?
I already have the code for checking similarity between two strings, and I only want to return that child if the similarity is greater than 0.25;
Example of a typical file structure (the paint brushes represent the isMat nodes):
and the object:
{
"name": "SubtlePBR",
"children": [
{
"name": "assets",
"children": [
{
"name": "minecraft",
"children": [
{
"name": "textures",
"children": [
{
"name": "block",
"children": [
{
"name": "acacia_leaves",
"children": [],
"isMat": true
},
{
"name": "acacia_log",
"children": [],
"isMat": true
}
]
}
]
}
]
}
]
}
]
}
After a few good hours I've figured it out: