return zero on mov_avg compute if no samples

This commit is contained in:
Mikayla Fischler 2024-04-27 19:50:35 -04:00
parent 35bf56663f
commit 826086951e

View File

@ -213,8 +213,13 @@ function util.mov_avg(length)
---@nodiscard
---@return number average
function public.compute()
if #data == 0 then return 0 end
local sum = 0
for i = 1, #data do sum = sum + data[i] end
for i = 1, #data do
sum = sum + data[i]
end
return sum / #data
end