find highest and lowest array value

i have a random numeric array value:

local array {9,5,7,1,2}

and i need to get both of highest and lowest value which would be 9 and 1. any way to do this on mikrotik?

:local array [:toarray (9,5,7,1,2)]
:local highest ($array->0)
:local lowest ($array->0)
:foreach i in=$array do={
:if ($i > $highest) do={:set $highest $i}
:if ($i < $lowest) do={:set $lowest $i}
}
:log info “highest = $highest”
:log info “lowest = $lowest”

Thank you!, appreciate it