|
|
|
@ -39,7 +39,7 @@ const breakDown = (node)=>{
|
|
|
|
return node;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const tree = breakDown({value:7});
|
|
|
|
const tree = breakDown({value:9});
|
|
|
|
|
|
|
|
|
|
|
|
console.dir(tree, {depth:null});
|
|
|
|
console.dir(tree, {depth:null});
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,15 +49,19 @@ const getLeaves = (node)=>{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let twoPathResult = [];
|
|
|
|
let twoPathResult = [];
|
|
|
|
const twoPathLeftValue = getLeaves(node.twoPath.left);
|
|
|
|
const twoPathLeftValue = getLeaves(node.twoPath.left);//2
|
|
|
|
const twoPathRightValue = getLeaves(node.twoPath.right);
|
|
|
|
const twoPathRightValue = getLeaves(node.twoPath.right);//[2,2]
|
|
|
|
if(Number.isInteger(twoPathRightValue)){
|
|
|
|
if(Number.isInteger(twoPathRightValue)){
|
|
|
|
twoPathResult[0] = twoPathLeftValue;
|
|
|
|
twoPathResult[0] = twoPathLeftValue;
|
|
|
|
twoPathResult[1] = twoPathRightValue;
|
|
|
|
twoPathResult[1] = twoPathRightValue;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
twoPathRightValue[0].unshift(twoPathLeftValue)
|
|
|
|
if(Number.isInteger(twoPathRightValue[0])){
|
|
|
|
twoPathRightValue[1].unshift(twoPathLeftValue);
|
|
|
|
twoPathRightValue.unshift(twoPathLeftValue);
|
|
|
|
twoPathResult = twoPathRightValue;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
twoPathRightValue[0].unshift(twoPathLeftValue)
|
|
|
|
|
|
|
|
twoPathRightValue[1].unshift(twoPathLeftValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
twoPathResult = twoPathRightValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let threePathResult = [];
|
|
|
|
let threePathResult = [];
|
|
|
|
|