wea.min, wea.max: add API functions

This commit is contained in:
Starbeamrainbowlabs 2021-05-29 23:13:10 +01:00
parent c7c6a848dc
commit b23f353b19
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2

@ -19,12 +19,43 @@ function worldeditadditions.sum(list)
return sum return sum
end end
--- Calculates the mean of all the numbers in the given list.
-- @param list number[] The list (table) of numbers to calculate the mean for.
-- @returns The mean of the numbers in the given table.
function worldeditadditions.average(list) function worldeditadditions.average(list)
if #list == 0 then return 0 end if #list == 0 then return 0 end
return worldeditadditions.sum(list) / #list return worldeditadditions.sum(list) / #list
end end
--- Finds the minimum value in the given list.
-- @param list number[] The list (table) of numbers to find the minimum value of.
-- @returns number The minimum value in the given list.
function worldeditadditions.min(list)
if #list == 0 then return nil end
local min = nil
for i,value in ipairs(list) do
if min == nil or min > value then
min = value
end
end
return min
end
--- Finds the maximum value in the given list.
-- @param list number[] The list (table) of numbers to find the maximum value of.
-- @returns number The maximum value in the given list.
function worldeditadditions.max(list)
if #list == 0 then return nil end
local max = nil
for i,value in ipairs(list) do
if max == nil or max < value then
max = value
end
end
return max
end
--- Returns the minetest.get_us_time() in ms --- Returns the minetest.get_us_time() in ms
-- @return float -- @return float
function worldeditadditions.get_ms_time() function worldeditadditions.get_ms_time()