From 60ce6f3e535db71f9fdc9d782329e3cadb4ec835 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 6 Jul 2021 23:22:41 +0200 Subject: [PATCH] Ignore NaN in table.count_values --- table.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/table.lua b/table.lua index f0a7724..3c3c200 100644 --- a/table.lua +++ b/table.lua @@ -339,9 +339,12 @@ end -- Recursively counts occurences of values in a table -- 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) local counts = {} local function count_values_(value) + -- Ignore NaN + if value ~= value then return end local count = counts[value] counts[value] = (count or 0) + 1 if not count and type(value) == "table" then