
Eric Lippert's challenge - cleanerer
By: a guest on
Sep 10th, 2010 | syntax:
C# | size: 0.57 KB | hits: 50 | expires: Never
sealed class Dumper
{
static public string Dump(Node root)
{
return Dump( root, "" );
}
static private string Dump(Node node, string indent)
{
return node.Text + "\n" +
( node.Children.Count == 0
? "" : node.Children.Take(node.Children.Count - 1).
Aggregate(string.Empty, (results, child) =>
results + indent + "├─" + Dump(child, indent + "│ ") )
+ indent + "└─" + Dump(node.Children.Last(), indent + " " ) );
}
}