Comma quibbling: Difference between revisions
Content deleted Content added
Undo revision 168692 by Bearophile Spaces, punctuation, or "and" would make the output look odd. |
No edit summary |
||
Line 84: | Line 84: | ||
if words(list) < 2 then return list |
if words(list) < 2 then return list |
||
return translate(strip(subword(list,1,words(list)-1)),',',' ') 'and' word(list,words(list)) |
return translate(strip(subword(list,1,words(list)-1)),',',' ') 'and' word(list,words(list)) |
||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
{ABC} |
|||
{ABC and DEF} |
|||
{ABC,DEF,G and H}</pre> |
|||
=={{header|Rust}}== |
|||
<lang Rust> |
|||
fn quibble(seq: &[~str]) -> ~str { |
|||
match seq { |
|||
[] => ~"{}", |
|||
[ref w] => fmt!("{%s}", *w), |
|||
[..ws, ref w] => fmt!("{%s and %s}", ws.connect(", "), *w), |
|||
} |
|||
} |
|||
fn main() { |
|||
println(quibble([~"ABC"])); |
|||
println(quibble([~"ABC", ~"DEF"])); |
|||
println(quibble([~"ABC", ~"DEF", ~"G", ~"H"])); |
|||
} |
|||
</lang> |
</lang> |
||