-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlittleTree.js
More file actions
45 lines (32 loc) · 940 Bytes
/
littleTree.js
File metadata and controls
45 lines (32 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var newTree = {children: []};
var parent;
var parentModel;
var counter=0;
var littleTree = function (node, depth){
parent = newTree;
recursiveCrawl(node, depth);
return newTree;
}
var recursiveCrawl = function( node , depth ){
var deepness = depth - 1;
if (deepness < 1) {return};
console.log(node.name);
var thisNode = {};
thisNode.parent = parent;
thisNode.valu
e = node.value;
thisNode.name = node.name;
//thisNode.children = node.children;
thisNode.children = [];
parent.children.push(thisNode);
console.log(thisNode.name);
if ( (node.children.length > 0) && (depth > 1) ) {
parent = thisNode;
for (var i = 0; i < node.children.length; i++) {
recursiveCrawl(node.children[i], deepness )
}
}
//when this runs out of children, reset the parent as 'parent' so as to operate on siblings
//ok, why is it recursing infinitely?? or is something else causing it to crash?
parent = thisNode.parent;
}