Conde2 0 #1 Posted July 30, 2011 Bom como eu participo do grupo de suporte e um cara pediu isso vim trazer aqui pra vocês. Bom uso =) function table.maxValue(array) t = {} for _, check in pairs(array) do if type(check) == "number" then table.insert(t, check) end end table.sort(t, function(a, return a > b end) return t[1] end Ao printar print(table.maxValue({7,2, "a"}))o valor retornado será o maior da tabela sendo assim: 7 Share this post Link to post Share on other sites
Jovial 2 #2 Posted January 5, 2012 Ineficiência extrema Desse jeito ela tem o mesmo comportamento da sua mas sem fazer a cópia do array e a ordenação, ambos desnecessários nesse caso. function table.maxValue(array) local max for _, v in pairs(array) do if type(v) == "number" then if( not max or v > max )then max = v end end end return max end Share this post Link to post Share on other sites