From 782bb1d9bcf87e85456867d9ed0ecfddb565906e Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Wed, 19 Apr 2023 14:52:21 -0400 Subject: [PATCH] works up to and including 7 --- random.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/random.js b/random.js index 0fe7a8e..4f47163 100644 --- a/random.js +++ b/random.js @@ -39,7 +39,7 @@ const breakDown = (node)=>{ return node; } -const tree = breakDown({value:7}); +const tree = breakDown({value:9}); console.dir(tree, {depth:null}); @@ -49,15 +49,19 @@ const getLeaves = (node)=>{ } let twoPathResult = []; - const twoPathLeftValue = getLeaves(node.twoPath.left); - const twoPathRightValue = getLeaves(node.twoPath.right); + const twoPathLeftValue = getLeaves(node.twoPath.left);//2 + const twoPathRightValue = getLeaves(node.twoPath.right);//[2,2] if(Number.isInteger(twoPathRightValue)){ twoPathResult[0] = twoPathLeftValue; twoPathResult[1] = twoPathRightValue; } else { - twoPathRightValue[0].unshift(twoPathLeftValue) - twoPathRightValue[1].unshift(twoPathLeftValue); - twoPathResult = twoPathRightValue; + if(Number.isInteger(twoPathRightValue[0])){ + twoPathRightValue.unshift(twoPathLeftValue); + } else { + twoPathRightValue[0].unshift(twoPathLeftValue) + twoPathRightValue[1].unshift(twoPathLeftValue); + } + twoPathResult = twoPathRightValue; } let threePathResult = [];