From 6f9177bacf6ec595c06c163df5842df2f7c87b29 Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Wed, 19 Apr 2023 16:49:41 -0400 Subject: [PATCH] 9 works --- random.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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; }