Junior — Senior
Collecting all node values of the tree
livecode
Task condition
It is required to implement the function collectValues, which returns an array with the values of all nodes of the given tree.
const root = {
value: 1,
children: [
{
value: 2,
children: [
{ value: 4 },
{ value: 5 },
],
},
{
value: 3,
children: [
{ value: 6 },
{ value: 7 },
],
},
],
};
collectValues(root); // => [1, 2, 3, 4, 5, 6, 7]