score:2

I would guess that the node that you pass into the second node as a child needs to be a reference to the first one, not the new Object that you are creating. Try this;

function flatten1() {
  var nodes = [];
  var node1 = {name: 'child1', size: 100, id: 1};
  nodes.push(node1);
  var node2 = {name: 'parent', children: [node1], id: 2};
  nodes.push(node2);
  return nodes;
}

If that works then it gives you some idea on how to shape the rest of your flatten algorithm.


Related Query