function high(scorel)
local highest = 0
for name, score in pairs(scorel) do
if score > highest then
highest = score
end
end
print(name)
end
打印得分最高的密钥,包括他或她的名字。
答案 0 :(得分:0)
您也只需记住名称:
eval
如果每个人的分数都相同,则您的算法不会选择组长,但也许正是您想要的。
UPD :领导层分开:
function high(scorel)
local leader, highest = nil, 0
for name, score in pairs(scorel) do
if score > highest then
leader, highest = name, score
end
end
return leader, highest
end
print (high(scores)) -- will print leader's name and score.
local leader, record = high(scores)
print (leader) -- abd this will print only the champion's name.