Search code examples
sortinglualua-table

[LUA]Getting most recurring integer in a table


i need to get the most recurring vIndex in a lua table structured like this:

{{id=0, vIndex = 0},{id=34, vIndex = 1},...}

what's the best way to do so?


Solution

  • Loop over each element in a table and keep track on the number of occurrences in another table where each value of vIndex being a key. Then loop over the second table to find the element with the max value. This will be your most frequent vIndex.