You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
//const numBeats = Math.ceil(Math.random()*9);
|
|
|
|
//let resultString = '';
|
|
//const instructionPosibilities = [ 'n', 'p', 'm', 'b' ]
|
|
|
|
//for(let i = 1; i <= numBeats; i++){
|
|
//const instructionIndex = Math.floor(Math.random()*instructionPosibilities.length);
|
|
|
|
//resultString += instructionPosibilities[instructionIndex] + ' ';
|
|
//}
|
|
|
|
//console.log(resultString);
|
|
|
|
|
|
//5: 3+2, 2+3
|
|
//6: 2+2+2, 3+3
|
|
//7: 2+2+3, 2+3+2, 3+2+2
|
|
//8: 2+3+3, 3+2+3, 3+3+2
|
|
//9: 3+3+3, 2+2+2+3, 2+2+3+2, 2+3+2+2, 3+2+2+2
|
|
|
|
const breakDown = (node)=>{
|
|
|
|
if(node.value < 4){
|
|
return node
|
|
}
|
|
|
|
//2 path
|
|
node.twoPath = {};
|
|
node.twoPath.left = { value: 2 }
|
|
node.twoPath.right = breakDown({value:node.value-2})
|
|
|
|
//3 path
|
|
if(node.value > 4){
|
|
node.threePath = {}
|
|
node.threePath.left = { value: 3 }
|
|
node.threePath.right = breakDown({value:node.value-3})
|
|
}
|
|
|
|
return node;
|
|
}
|
|
|
|
const tree = breakDown({value:9});
|
|
|
|
console.dir(tree, {depth:null});
|
|
|
|
//const getLeaves = (node, leafArray)=>{
|
|
//if(node.left === undefined && node.right === undefined){
|
|
//leafArray.push(node.value);
|
|
//} else {
|
|
//getLeaves(node.left, leafArray)
|
|
//getLeaves(node.right, leafArray)
|
|
//}
|
|
//return leafArray;
|
|
//}
|
|
//const leaves = getLeaves(tree, []);
|
|
|
|
//console.log(leaves);
|