Get shortest/longest string in array

The naive implementation is actually hard to beat:

function minmax_elements(arr)
    minl = maxl = arr[1]
    smin = smax = sizeof(minl)
    for a in arr
        sa = sizeof(a)
        if sa > smax
            maxl, smax = a, sa
        elseif sa < smin
            minl, smin = a, sa
        end
    end
    minl, maxl
end 

arr = ["hello", "beautiful", "world", "!"];
@btime minmax_elements($arr)
  5.700 ns (0 allocations: 0 bytes)
("!", "beautiful")
2 Likes