In my golf game, after the last player falls in the final hole, each player’s strokes are tallied up and assigned to a key, which is the player’s name. How do I find the smallest value out of them all, and also get its corresponding key?
1 Like
local smallestValue, smallestKey = math.huge -- The largest number Lua can represent, just makes the loop check code easier to write
for key, value in pairs(dict) do
if value < smallestValue then
smallestKey, smallestValue = key, value
end
end
if smallestKey then
-- code
end
7 Likes