nv-cli-ifelse
Version:
cli,to write many if else
48 lines (39 loc) • 1.03 kB
JavaScript
const {add_repr} = require("nv-facutil-basic");
const Branch = require("./branch");
const Forest = require("nv-data-tree-csp-forest");
function _repr(that) {
let sedfs = that.$sedfs_.slice(1);
sedfs.pop();
let ary = sedfs.map(
r=>{
if(r[1]==='open') {
return(r[0].open_str_)
} else {
return(r[0].close_str_)
}
}
)
let s = "\n" + ary.join("\n\n")
s = s.replace(/[\n]{2,}/g,"\n\n")
return(s+'\n')
}
add_repr(Branch,_repr);
////
function build(size=10000,depth=1,count=10) {
let forest = new Forest(size)
let rt = forest.node(Branch);
let unhandled = [rt]
let d =0 ;
let next_unhandled = []
while(d<depth) {
for(let nd of unhandled) {
let children = nd.$append_children(count);
next_unhandled = next_unhandled.concat(children)
}
unhandled = next_unhandled;
next_unhandled = [];
d = d + 1;
}
return(rt)
}
module.exports = build;