Comma quibbling: Difference between revisions
Content added Content deleted
No edit summary |
m (whitespace/formatting) |
||
Line 17: | Line 17: | ||
=={{header|C#}}== |
=={{header|C#}}== |
||
<lang csharp> |
<lang csharp>public static string Quibble(string[] input) |
||
{ |
|||
public static string Quibble(string[] input) |
|||
var len = input.Length; |
|||
return "{ " + |
|||
var len = input.Length; |
|||
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) |
|||
{ |
|||
{ |
|||
Console.WriteLine(Quibble(new string[] { })); |
|||
Console.WriteLine(Quibble(new[] { "A" })); |
|||
Console.WriteLine(Quibble(new[] { "A", "B" })); |
|||
Console.WriteLine(Quibble(new[] { "A", "B", "C" })); |
|||
Console.WriteLine(Quibble(new[] { "A", "B", "C", "D" })); |
|||
Console.WriteLine(Quibble(new[] { "A", "B", "C", "D", "E" })); |
|||
⚫ | |||
} |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>{ } |
<pre>{ } |
||
Line 121: | Line 119: | ||
quibble ["ABC"; "DEF"] |
quibble ["ABC"; "DEF"] |
||
quibble ["ABC"; "DEF"; "G"] |
quibble ["ABC"; "DEF"; "G"] |
||
quibble ["ABC"; "DEF"; "G"; "H"] |
quibble ["ABC"; "DEF"; "G"; "H"]</lang> |
||
</lang> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
Line 219: | Line 216: | ||
End |
End |
||
Return '{'result'}'</lang> |
Return '{'result'}'</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |