Ignore NaN in table.count_values

This commit is contained in:
Lars Mueller 2021-07-06 23:22:41 +02:00
parent 2e9db04632
commit 60ce6f3e53

@ -339,9 +339,12 @@ end
-- Recursively counts occurences of values in a table -- Recursively counts occurences of values in a table
-- Also counts primitive values like boolean and number -- Also counts primitive values like boolean and number
-- Does not count NaN, because that doesn't work as a table index
function count_values(value) function count_values(value)
local counts = {} local counts = {}
local function count_values_(value) local function count_values_(value)
-- Ignore NaN
if value ~= value then return end
local count = counts[value] local count = counts[value]
counts[value] = (count or 0) + 1 counts[value] = (count or 0) + 1
if not count and type(value) == "table" then if not count and type(value) == "table" then