Greatest element of a list: Difference between revisions
Content added Content deleted
(→Joy: add) |
(→{{header|Vim Script}}: Fix indentation (tabs → spaces)) |
||
Line 4,534: | Line 4,534: | ||
for strings (with configurable ignore-case): |
for strings (with configurable ignore-case): |
||
<syntaxhighlight lang="vim">function! Max(list, ...) |
<syntaxhighlight lang="vim">function! Max(list, ...) |
||
" {list} |
" {list} list of strings |
||
" {a:1} |
" {a:1} 'i': ignore case, 'I': match case, otherwise use 'ignorecase' option |
||
if empty(a:list) |
if empty(a:list) |
||
return 0 |
|||
endif |
endif |
||
let gt_op = a:0>=1 ? get({'i': '>?', 'I': '>#'}, a:1, '>') : '>' |
let gt_op = a:0>=1 ? get({'i': '>?', 'I': '>#'}, a:1, '>') : '>' |
||
Line 4,545: | Line 4,545: | ||
let idx = 1 |
let idx = 1 |
||
while idx < len |
while idx < len |
||
if eval(cmp_expr) |
|||
let maxval = a:list[idx] |
|||
endif |
|||
let idx += 1 |
|||
endwhile |
endwhile |
||
return maxval |
return maxval |