Difference between revisions of "Template:Smart lookup"
Jump to navigation
Jump to search
Kevin Wang (talk | contribs) m |
Kevin Wang (talk | contribs) m |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | <includeonly>{{ | + | <includeonly>{{List lookup helper|{{{1}}}}}{{#vardefine:index|{{{2|1}}}}}<!-- |
| − | + | -->{{#ifexpr:{{#var:index}}<={{#var:length}}<!-- | |
| − | --> | + | if index is less than length of list, return immediately |
| − | + | -->|{{#var:entry_{{#var: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. | ||
| − | This behavior was extracted from [[Template:Quick links smart lingo]]. | + | This behavior was originally extracted from [[Template:Quick links smart lingo|Quick links smart lingo]] and was refactored to use [[Template:List lookup helper|List lookup helper]]. |
<pre> | <pre> | ||
| − | {{Smart lookup | + | {{Smart lookup|QBWiki:Quick links/lingo|1}} |
| − | |Quick links lingo | + | |
| − | |1 | + | {{Smart lookup|QBWiki:Quick links/lingo|99}} |
| − | }} | ||
</pre> | </pre> | ||
| − | {{Smart lookup|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"?