Add printTree() to List

This commit is contained in:
haad 2016-03-11 14:10:56 +01:00
parent beead609c1
commit f258a53bd7

View File

@ -95,6 +95,18 @@ class List {
static isReferencedInChain(all, item) {
return Lazy(all).reverse().find((e) => e.hasChild(item)) !== undefined;
}
printTree() {
const printCurrent = (f, padding) => {
padding += " |";
let s = padding + "-" + f.compactId + " '" + f.data + "'\n";
if(f.next.length > 0) {
s += f.next.map((e) => printCurrent(e, padding)).join("");
}
return s;
}
console.log(" LIST\n" + this.items.reverse().map((e) => printCurrent(e, "")).join(""));
}
}
module.exports = List;