Pluto
Pluto copied to clipboard
table.countvalues
function table.countvalues(t)
local counts = {}
for t as elm do
counts[elm] = (counts[elm] ?? 0) + 1
end
return counts
end
Could consider table.values() instead that returns an array of values
Wdym?
local assert = require("assert")
local t = { a = 1, b = 2, c = 3 }
assert.equals({ 1, 2, 3 }, t:values())
Then you could query for length if you needed.
How does that solve this?