got 7 to almost work. left side too nested

master
Matthew Huntington 3 years ago
parent 5031b6402a
commit dcda81a325

@ -47,16 +47,38 @@ const getLeaves = (node)=>{
if(node.twoPath === undefined){ if(node.twoPath === undefined){
return node.value; return node.value;
} }
const twoPathLeftValue = getLeaves(node.twoPath.left);
const twoPathRightValue = getLeaves(node.twoPath.right); let twoPathResult = [];
const twoPathLeftValue = getLeaves(node.twoPath.left); //2
const twoPathRightValue = getLeaves(node.twoPath.right); //[[2,3],[3,2]]
if(Number.isInteger(twoPathRightValue)){
twoPathResult[0] = twoPathLeftValue;
twoPathResult[1] = twoPathRightValue;
} else {
//[2] [[2,3],[3,2]]
twoPathRightValue[0].unshift(twoPathLeftValue)
twoPathRightValue[1].unshift(twoPathLeftValue);
twoPathResult = twoPathRightValue;
}
let threePathResult = [];
if(node.threePath !== undefined){ if(node.threePath !== undefined){
const threePathLeftValue = getLeaves(node.threePath.left); const threePathLeftValue = getLeaves(node.threePath.left);
const threePathRightValue = getLeaves(node.threePath.right); const threePathRightValue = getLeaves(node.threePath.right);
return [[twoPathLeftValue, twoPathRightValue], [threePathLeftValue, threePathRightValue]]; if(Number.isInteger(threePathRightValue)){
threePathResult[0] = threePathLeftValue;
threePathResult[1] = threePathRightValue;
} else {
threePathResult[0] = threePathLeftValue;
threePathResult = threePathResult.concat(threePathRightValue);
}
}
if(threePathResult.length === 0){
return twoPathResult;
} else {
return [twoPathResult, threePathResult]
} }
return [twoPathLeftValue, twoPathRightValue];
} }
const leaves = getLeaves(tree); const leaves = getLeaves(tree);

Loading…
Cancel
Save