Function that returns a table containing missing number in a sequence

“1, 2, 3, 7” → {4, 5, 6}
{-1, 4} → {0, 1, 2, 3}

This should be pretty easy to make, you just need to iterate through all the numbers and compare the last number to the current number and see if the difference is > 1, then you can fill in any gaps.

local function getMissingNumbers(numbers: {number}): {number}
	table.sort(numbers)
	
	local missing: {number} = {}
	local prev: number?
	for _, num in numbers do
		if not prev then
			prev = num
			continue
		end
		
		-- check if difference > 1
		if num - prev > 1 then
			-- add missing number(s) to list
			for miss = prev + 1, num - 1 do
				table.insert(missing, miss)
			end
		end
		
		prev = num
	end
	
	return missing
end

print(getMissingNumbers({-1, 4})) --> {0, 1, 2, 3}

oh is that how you define a expected table value in a function!? anyways thankers :3