I'm trying to build an iterator on JS that will take a tree and on each iteration return next possible subtree.
Here is an example of source tree:
{
name: 'A',
children: [
{
name: 'B',
children: [
{
name: 'E'
},
{
name: 'F'
},
]
},
{
name: 'C',
}
]
}
The result should be three iterations
1. {
name: 'A',
children: [
{
name: 'B',
children: [
{
name: 'E'
}
]
}
]
}
2. {
name: 'A',
children: [
{
name: 'B',
children: [
{
name: 'F'
}
]
}
]
}
3. {
name: 'A',
children: [
{
name: 'C',
}
]
}
Could someone give me a hint or point to the right direction of how this problem could be solved?
Thanks!