Comma quibbling: Difference between revisions
Content deleted Content added
→{{header|Perl}}: style |
→{{header|C#}}: Remove extra spaces |
||
Line 37: | Line 37: | ||
=={{header|C#}}== |
=={{header|C#}}== |
||
{{incorrect|C#|Wrong examples. Extra spaces.}} |
|||
<lang csharp>public static string Quibble(string[] input) |
<lang csharp>public static string Quibble(string[] input) |
||
{ |
{ |
||
var len = input.Length; |
var len = input.Length; |
||
return "{ |
return "{" + |
||
String.Join("", input.Take(len - 2).Select(n => n + ", ") |
String.Join("", input.Take(len - 2).Select(n => n + ", ") |
||
.Concat(input.Skip(len < 2 ? len : len - 2).Take(1).Select(n => n + " and "))) |
.Concat(input.Skip(len < 2 ? len : len - 2).Take(1).Select(n => n + " and "))) |
||
+ (input.LastOrDefault() ?? "") + " |
+ (input.LastOrDefault() ?? "") + "}"; |
||
} |
} |
||
static void Main(string[] args) |
static void Main(string[] args) |
||
Line 56: | Line 55: | ||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
<pre>{ |
<pre>{} |
||
{ |
{A} |
||
{ |
{A and B} |
||
{ |
{A, B and C} |
||
{ |
{A, B, C and D} |
||
{ |
{A, B, C, D and E}</pre> |
||
=={{header|C++}}== |
=={{header|C++}}== |