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

How to find most common occurrence?

Asked by 5 years ago
Edited 5 years ago

So I have a function that loops through a 3D array and inserts all the values in the 3d array into a normal 1D array, but I would like to be able to find the most common occurrence between the numbers and I am not sure how to do that.

Here is my code.

local array3d = {

{

{1, 2, 3, 4}, {1, 2, 2, 2, 4}

}

}



local commonOccurrence = { }





local function commonValue(tab, common)

for i = 1, #tab do

for v = 1, #tab[i] do

for k = 1, #tab[i][v] do

common[i] = tab[i][v][k]

end

end

end







end



commonValue(array3d, commonOccurrence)

Answer this question