|
|
|
|
@ -43,20 +43,21 @@ const tree = breakDown({value:5});
|
|
|
|
|
|
|
|
|
|
console.dir(tree, {depth:null});
|
|
|
|
|
|
|
|
|
|
const getLeaves = (node, leafArray)=>{
|
|
|
|
|
const getLeaves = (node)=>{
|
|
|
|
|
if(node.twoPath === undefined){
|
|
|
|
|
return node.value;
|
|
|
|
|
}
|
|
|
|
|
const leftValue = getLeaves(node.twoPath.left, leafArray)
|
|
|
|
|
const rightValue = getLeaves(node.twoPath.right, leafArray)
|
|
|
|
|
leafArray.push([leftValue, rightValue]);
|
|
|
|
|
const twoLeftValue = getLeaves(node.twoPath.left);
|
|
|
|
|
const twoRightValue = getLeaves(node.twoPath.right);
|
|
|
|
|
|
|
|
|
|
if(node.threePath !== undefined){
|
|
|
|
|
const leftValue = getLeaves(node.threePath.left, leafArray)
|
|
|
|
|
const rightValue = getLeaves(node.threePath.right, leafArray)
|
|
|
|
|
leafArray.push([leftValue, rightValue]);
|
|
|
|
|
const threeLeftValue = getLeaves(node.twoPath.left);
|
|
|
|
|
const threeRightValue = getLeaves(node.twoPath.right);
|
|
|
|
|
return [[twoLeftValue, twoRightValue], [threeLeftValue, threeRightValue]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [twoLeftValue, twoRightValue];
|
|
|
|
|
}
|
|
|
|
|
const leaves = []
|
|
|
|
|
getLeaves(tree, leaves);
|
|
|
|
|
const leaves = getLeaves(tree);
|
|
|
|
|
|
|
|
|
|
console.log(leaves);
|
|
|
|
|
|