Created
August 30, 2019 04:06
-
-
Save venkatperi/145ce33f4e19553a1ed9972e2fcb1369 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toAsciiTree(tree: any, prefix = "", isTail = true): string | null { | |
if (!tree) { | |
return null | |
} | |
let children = tree.children || [] | |
return [prefix, isTail ? "└" : "├", " ", tree.name, '\n'] | |
.concat(children.map((c: any, i: number) => toAsciiTree(c, | |
prefix + (isTail ? " " : "│ "), i >= children.length - 1))) | |
.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment