Difference between revisions of "Template:Smart lookup"
Jump to navigation
Jump to search
Kevin Wang (talk | contribs) |
Kevin Wang (talk | contribs) m |
||
| Line 1: | Line 1: | ||
| − | <includeonly>{{#vardefine:page|{{{1}}}}}{{#vardefine:index|{{{2|1}}}}}{{Add|index|1}}{{#if:{{{{#var:page}}|{{#var:index}}}} | + | <includeonly>{{#vardefine:page|{{{1}}}}}{{#vardefine:index|{{{2|1}}}}}{{Add|index|1}}{{#if:{{{{#var:page}}|{{#var:index}}}}<!-- |
| − | |{{{{#var:page}}|{{#var:index}}}} | + | if the page at index exists, return immediately and be done with it |
| + | -->|{{{{#var:page}}|{{#var:index}}}} | ||
|{{#vardefine:minindex|{{#var:index}}}}{{#vardefine:maxindex|1}}<!-- | |{{#vardefine:minindex|{{#var:index}}}}{{#vardefine:maxindex|1}}<!-- | ||
| − | + | otherwise it is out of bounds and we need to wrap around - since we need the total size, do a binary search for last list entry for fun | |
-->{{#dowhile: | -->{{#dowhile: | ||
|{{#ifexpr:{{#var:maxindex}}+1<{{#var:minindex}}|continue}} | |{{#ifexpr:{{#var:maxindex}}+1<{{#var:minindex}}|continue}} | ||
Revision as of 17:38, 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 extracted from Template:Quick links smart lingo.
{{Smart lookup
|Quick links lingo <!-- page containing list -->
|1 <!-- index -->
}}
Confused what a "vulcher" is?