ipairs refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-11-26 18:28:01 +01:00
parent 90d92ecc34
commit 3f3c7b28fc
9 changed files with 47 additions and 39 deletions
+3 -3
View File
@@ -97,10 +97,10 @@ end
function weighted_median(list)
sort(list, function(a,b) return a.value < b.value end)
local weight = 0
for _, element in ipairs(list) do
weight = weight + element.weight
for i = 1, getn(list) do
weight = weight + list[i].weight
if weight >= .5 then
return element.value
return list[i].value
end
end
end
+2 -1
View File
@@ -73,7 +73,8 @@ function extend_tooltip(tooltip, link, quantity)
if aux_tooltip_disenchant_distribution then
tooltip:AddLine('Disenchants into:', color.tooltip.disenchant.distribution())
sort(distribution, function(a,b) return a.probability > b.probability end)
for _, event in ipairs(distribution) do
for i = 1, getn(distribution) do
local event = distribution[i]
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:' .. event.item_id, event.min_quantity, event.max_quantity), color.tooltip.disenchant.distribution())
end
end