RosettaCodeData/Task/Averages-Mode/Pluto/averages-mode.pluto
2026-04-30 12:34:36 -04:00

23 lines
542 B
Text

local fmt = require "fmt"
local function mode(a)
local t = a:countvalues()
local max = t:values():max()
local res = {}
for k, v in t do
if v == max then res:insert(k) end
end
return res
end
local tests = {
{1, 2, 5, -5, -9.5, 3.14159},
{ 1, "blue", 2, 7.5, 5, "green", "red", 5, 2, "blue", "white" },
{1, 2, 3, 1, 2, 4, 2, 5, 2, 3, 3, 1, 3, 6},
{.2, .7, .1, .8, .2},
{"two", 7, 1, 8, "two", 8},
"Hello there world":split(""),
{}
}
for tests as test do fmt.lprint(mode(test)) end