assuming an interface such as:
interface CustomNode {
id: string;
children: CustomNode[];
}
If I have an object such as:
nodes: CustomNode[] = [
{
id: 'A',
children: [
{
id: 'B',
children: [
{
id: 'C',
children: [
{
id: 'D',
children: []
},
{
id: 'E',
children: []
}
]
}
]
}
]
}
]
how could I create a function that removes a given 'CustomNode' and its children?
I prefer a Typescript/ES6 solution, but am okay with any general solution (e.g. Typescript, Javascript, ES, dependencies such as lodash, etc)
e.g. How can I remove CustomNode with ID 'C' and its children?
nodes = removeIfExists(nodes, 'C');
removeIfExists(nodes: CustomNode[], removeId: string) {
// ...
}