Difference between revisions of "Serial"

(probably inefficient way to do this but it works)
 
m (check if list length is greater than 1)
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>

Revision as of 15:28, 19 August 2023

Description

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

Usage

{{Serial|<input>}}

Parameters

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