function mode(table)
if #table == 0 then return nil end
local modeMap = {}
local maxEl = table[1]
local maxCount = 1
for i, v in ipairs(table) do
modeMap[v] = (modeMap[v] or 0) + 1
if modeMap[v] > maxCount then
maxEl = v
maxCount = modeMap[v]
end
end
return maxEl
end
print(mode({"text", "go", "text", "", "go", "text"})) -- text
print(mode({"text", "go", "go", "go", "text", "", "go", "text"})) -- go