mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-22 19:45:02 +00:00
wea.min, wea.max: add API functions
This commit is contained in:
parent
c7c6a848dc
commit
b23f353b19
1 changed files with 32 additions and 1 deletions
|
@ -19,12 +19,43 @@ function worldeditadditions.sum(list)
|
|||
return sum
|
||||
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)
|
||||
if #list == 0 then return 0 end
|
||||
return worldeditadditions.sum(list) / #list
|
||||
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
|
||||
-- @return float
|
||||
function worldeditadditions.get_ms_time()
|
||||
|
|
Loading…
Reference in a new issue