Difference between revisions of "Serial"

(probably inefficient way to do this but it works)
 
m (Stratonian moved page Comma list to Serial without leaving a redirect: better name)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<includeonly>{{#arraydefine:list|{{{1}}}}}<!-- define array
 
<includeonly>{{#arraydefine:list|{{{1}}}}}<!-- define array
-->{{#arrayslice:new|list|0|-1}}{{#arrayprint:new}}<!-- print all elements but last one
+
-->{{#ifexpr:{{#arraysize:list}} > 1<!-- if list length is greater than 1
 +
-->|{{#arrayslice:new|list|0|-1}}{{#arrayprint:new}}<!-- print all elements but last one
 
-->, and {{#arrayindex:list|-1}}<!-- print ', and' with last element
 
-->, and {{#arrayindex:list|-1}}<!-- print ', and' with last element
 +
-->|{{#arrayprint:list}}}}<!-- else print list as normal
 
--></includeonly><noinclude>{{{{PAGENAME}}/Documentation}}</noinclude>
 
--></includeonly><noinclude>{{{{PAGENAME}}/Documentation}}</noinclude>

Latest revision as of 15:28, 19 August 2023

Description[edit]

Outputs a comma list with 'and' before the last element using a serial comma.

Usage[edit]

{{Serial|<input>}}

Parameters[edit]

Arrow.png1: The input list.
Required.
Notes: Elements must be separated by commas.