I have a tree structure like below,
{
uid: 1,
children: [
{
uid: 2
},
{
uid: 3,
children: [
{
uid: 4
},
{
uid: 5,
children: [
{
uid: 6
}
]
},
{
uid: 7
}
]
}
]
}
Now, I want to search tree structure by uid and need output as a tree structure(i.e along with its parents, but no siblings)
For example, if I search tree structure for "uid: 4", output result should be something like below,
{
uid: 1,
children: [
{
uid: 3
children: [
{
uid: 4
}
]
}
]
}
I tried recursion but I failed to fetch matching elements along with parents