Comma quibbling: Difference between revisions

Add lang example
(Add lang example)
Line 2,345:
["ABC", "DEF"] -> {ABC and DEF}
["ABC", "DEF", "G", "H"] -> {ABC, DEF, G and H}
</pre>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
fp.quibble = (&words) -> {
$len $= @&words
$output = \{\e
$i
repeat($[i], $len) {
$output += &words[$i] ||| ($i == -|$len?\e:($i == $len - 2?\sand\s:\,\s))
}
$output += \}\e
return $output
}
 
fn.println(fp.quibble(fn.arrayOf()))
fn.println(fp.quibble(fn.arrayOf(ABC)))
fn.println(fp.quibble(fn.arrayOf(ABC, DEF)))
fn.println(fp.quibble(fn.arrayOf(ABC, DEF, G, H)))
</syntaxhighlight>
 
{{out}}
<pre>
{}
{ABC}
{ABC and DEF}
{ABC, DEF, G and H}
</pre>
 
168

edits