
Eric Lippert's challenge
By: a guest on
Sep 10th, 2010 | syntax:
C# | size: 0.68 KB | hits: 38 | expires: Never
sealed class Dumper
{
static public string Dump(Node root)
{
return root.Text + "\n" + DumpChildren( root, "" );
}
static private string DumpChildren(Node node, string indent)
{
return node.Children.Count > 0
? string.Join( "", node.Children.Take(node.Children.Count - 1).ToList()
.ConvertAll( new Converter<Node, String>( child => string.Format("{0}├─{1}\n{2}", indent, child.Text, DumpChildren(child, indent + "│ ") ) ) ).ToArray() )
+ string.Format("{0}└─{1}\n{2}", indent, node.Children.Last().Text, DumpChildren(node.Children.Last(), indent + " ") )
: "";
}
}