Here is the code snippet, this goes into an infinite loop - with the "too much recursion error".
SW = {
WData : {
wf : {
roots : [852,1517,1523,1540],
leaves : [],
features : {
852: { "cf":"855,1848"},
1517: { "cf":"1929,1930"},
1523: { "cf":""},
1540: { "cf":"1546,1549"},
855: { "cf":"" },
1848: { "cf":""},
1929: { "cf":""},
1930: { "cf":""},
1546: { "cf":"1600"},
1549: { "cf":""},
1600: { "cf":""}
}
}
},
init: function init(){
this.buildTree();
//console.log(this.WData.wf.leaves);
},
buildTree : function(){
this.getLeaves(this.WData.wf.roots);
},
getLeaves: function(roots){
for(var i in roots){
var root = this.WData.wf.roots[i];
if( this.WData.wf.features[ root ].cf === ""){
this.WData.wf.leaves.push( root );
return false;
}
else{
this.getLeaves( this.WData.wf.features[root].cf.split(',').map(Number) );
}
}
return false;
}
}
SW.init();
Not able to understand what is the problem here. I have a feeling i am making quite a simple mistake.