diff --git a/random.js b/random.js index e594705..cffd841 100644 --- a/random.js +++ b/random.js @@ -41,7 +41,7 @@ const breakDown = (node)=>{ const tree = breakDown({value:9}); -console.dir(tree, {depth:null}); +//console.dir(tree, {depth:null}); const getLeaves = (node)=>{ if(node.twoPath === undefined){ @@ -58,8 +58,9 @@ const getLeaves = (node)=>{ if(Number.isInteger(twoPathRightValue[0])){ twoPathRightValue.unshift(twoPathLeftValue); } else { - twoPathRightValue[0].unshift(twoPathLeftValue) - twoPathRightValue[1].unshift(twoPathLeftValue); + for(let subArray of twoPathRightValue){ + subArray.unshift(twoPathLeftValue); + } } twoPathResult = twoPathRightValue; } @@ -97,7 +98,11 @@ const getLeaves = (node)=>{ if(Number.isInteger(threePathResult)){ twoPathResult.push(threePathResult) } else { - twoPathResult.push(threePathResult[0]) + if(Number.isInteger(threePathResult[0])){ + twoPathResult.push(threePathResult) + } else { + twoPathResult = twoPathResult.concat(threePathResult); + } } return twoPathResult; }