Difference between revisions of "Template:Smart lookup"

From QBWiki
Jump to navigation Jump to search
m
m
 
Line 3: Line 3:
 
if index is less than length of list, return immediately
 
if index is less than length of list, return immediately
 
-->|{{#var:entry_{{#var:index}}}}
 
-->|{{#var:entry_{{#var:index}}}}
|{{#vardefine:adjusted_index|{{#expr:({{{2|1}}} mod {{#var:index}})}}}}{{#ifexpr:{{#var:adjusted_index}}=0|{{#vardefine:adjusted_index|{{#var:index}}}}}}{{#var:entry_{{#var:adjusted_index}}}}
+
|{{#vardefine:adjusted_index|{{#expr:({{#var:index}} mod {{#var:length}})+1}}}}{{#ifexpr:{{#var:adjusted_index}}=0|{{#vardefine:adjusted_index|{{#var:index}}}}}}{{#var:entry_{{#var:adjusted_index}}}}
 
}}</includeonly><noinclude>{{Template doc|
 
}}</includeonly><noinclude>{{Template doc|
 
Given a list and an index ''i'', return the (''i'' mod ''N'')-th entry in the list.
 
Given a list and an index ''i'', return the (''i'' mod ''N'')-th entry in the list.
Line 10: Line 10:
 
<pre>
 
<pre>
 
{{Smart lookup|QBWiki:Quick links/lingo|1}}
 
{{Smart lookup|QBWiki:Quick links/lingo|1}}
 +
 +
{{Smart lookup|QBWiki:Quick links/lingo|99}}
 
</pre>
 
</pre>
  
 
{{Smart lookup|QBWiki:Quick links/lingo|1}}
 
{{Smart lookup|QBWiki:Quick links/lingo|1}}
 +
 +
{{Smart lookup|QBWiki:Quick links/lingo|99}}
 
}}</noinclude>
 
}}</noinclude>

Latest revision as of 21:00, 14 December 2025

Template documentation

Given a list and an index i, return the (i mod N)-th entry in the list.

This behavior was originally extracted from Quick links smart lingo and was refactored to use List lookup helper.

{{Smart lookup|QBWiki:Quick links/lingo|1}}

{{Smart lookup|QBWiki:Quick links/lingo|99}}

Wondering why people keep saying "m"?

Heard something about the "canon"?