Skip to content

Commit 4a84517

Browse files
authored
Add math.getAverage() (#2234)
* Update math.lua * Update math.lua
1 parent 86b57b8 commit 4a84517

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lua/starfall/libs_sh/math.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,20 @@ math_library.easeOutQuint = math.ease.OutQuint
607607
-- @return number "Eased" Value
608608
math_library.easeOutSine = math.ease.OutSine
609609

610+
--- Returns the averaged of all numbers provided
611+
-- @class function
612+
-- @param table numbers Any amount of number values
613+
-- @return number Number average of all values
614+
function math_library.mean( numbers )
615+
checkluatype( numbers, TYPE_TABLE )
616+
617+
local sum = 0
618+
619+
for i = 1, #numbers do
620+
sum = sum + numbers[i]
621+
end
622+
623+
return sum / #numbers
624+
end
625+
610626
end

0 commit comments

Comments
 (0)