Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I count the frequency of values in a list? [closed]

Asked by 5 years ago

So, this may be a terrible terrible setup because its my first time trying one. But I am trying to do map voting and when the player votes their userId gets added to a table with the map they voted. and to get the frequency I tried doing this

local function countFreq(tab)
    local freq = {};
    for _, v in ipairs(tab) do
        freq[v] = (freq[v] or 0) + 1;
    end
    return freq;
end

Always returns nil even if there is votes, and or duplicate votes.

0
have you tried printing freq[v] after you changed it theking48989987 2147 — 5y
0
also semicolons aren't needed in roblox lua theking48989987 2147 — 5y
0
also what s the table "tab" supposed to contain? theking48989987 2147 — 5y
0
Holy illiterate. TheEpicObbyCreator 32 — 5y
View all comments (4 more)
0
semicolons why User#19524 175 — 5y
0
people who use semicolons > skrubs with spaghetti code ???? TheEpicObbyCreator 32 — 5y
0
thats just an excess burden though theking48989987 2147 — 5y
0
How, the semicolon is literally right next to shift it takes no extra work to press. Other languags I program in require it and I think Lua is more readable with it TheEpicObbyCreator 32 — 5y

Locked by EzraNehemiah_TF2

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 5 years ago

This got answered on the discord

Ad