Bash Missing Integer
missing_integer() {
local -n _a="$1"
local -a _sorted=($(printf '%s\n' "${_a[@]}" | sort -nu))
local _min=1 _v
for _v in "${_sorted[@]}"; do
if (( _v > 0 )); then
if (( _min != _v )); then
break
fi
((_min++))
fi
done
echo "$_min"
}
This records the positive numbers that exist, then returns the smallest positive value that is still missing.