-
What do you want to achieve?
I want to be able to find the best-optimized path to finding the max value of something -
What is the issue?
I have not done a benchmark test, so I am out to ask if I can receive a quick answer from DevForum. Otherwise, I will conduct the benchmark test on my own. -
What solutions have you tried so far?
I’ve attempted to look around the DevForum to see if I can find any answers related to what I asked, but I don’t think I was able to find a similar problem (or if I didn’t look hard enough).
-- Sort and Find Max
table.insert(playerScores, {"Roblox", 1})
table.insert(playerScores, {"OtherPlayer", 2})
table.insert(playerScores, {"NewPlayer", 3})
table.sort(playerScores, function(a, b)
return a[2] > b[2] -- compare current player to next player
end)
local max = playerScores[1]
-- max is NewPlayer
-- Find Max only
local maxPlayer = nil
local maxScore = 0
for _, player in pairs(playerScores) do
if maxPlayer == nil then
maxPlayer = player[1]
maxScore = player[2]
continue
end
if player[2] > maxScore then
maxPlayer = player[1]
maxScore = player[2]
continue
end
end