Skip to content

Instantly share code, notes, and snippets.

@venkatperi
Created August 30, 2019 04:06
Show Gist options
  • Save venkatperi/145ce33f4e19553a1ed9972e2fcb1369 to your computer and use it in GitHub Desktop.
Save venkatperi/145ce33f4e19553a1ed9972e2fcb1369 to your computer and use it in GitHub Desktop.
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