
Eric Lippert's challenge - cleaner
By: a guest on
Sep 10th, 2010 | syntax:
C# | size: 0.63 KB | hits: 47 | 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
? "" : node.Children.Take(node.Children.Count - 1).
Aggregate(string.Empty, (results, child) =>
results + indent + "├─" + child.Text + "\n" + DumpChildren(child, indent + "│ ") )
+ indent + "└─" + node.Children.Last().Text + "\n" + DumpChildren(node.Children.Last(), indent + " " );
}
}