Happy Early Access Launch! Please bear with us: We're doing our best to get the site updated. If we currently don't have what you're looking for, try checking our sister site, beastieball.info.
If you're looking to contribute to the site, we're happy to have you! Check out Beastiepedia:To Do List to see what needs done.
Find us in the Wishes Unlimited Discord in the "Beastiepedia: The Beastieball Wiki" thread in the Forums!
Module:HelperFunctions: Difference between revisions
From Beastiepedia: The Beastieball Wiki
FractalDiane (talk | contribs) mNo edit summary |
FractalDiane (talk | contribs) mNo edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
end | end | ||
return result | return tostring(result) | ||
end | |||
function p.average(...) | |||
local frame = mw.getCurrentFrame() | |||
local result = 0 | |||
local count = 0 | |||
for i,v in ipairs(frame.args) do | |||
result = result + tonumber(v) | |||
count = count + 1 | |||
end | |||
if count ~= 0 then | |||
return string.format("%.4g", result / count) | |||
else | |||
return tostring(0) | |||
end | |||
end | end | ||
return p | return p |
Latest revision as of 04:29, 20 November 2024
Documentation for this module may be created at Module:HelperFunctions/doc
-- Module for various useful helper functions local p = {} function p.sum(...) local frame = mw.getCurrentFrame() local result = 0 for i,v in ipairs(frame.args) do result = result + tonumber(v) end return tostring(result) end function p.average(...) local frame = mw.getCurrentFrame() local result = 0 local count = 0 for i,v in ipairs(frame.args) do result = result + tonumber(v) count = count + 1 end if count ~= 0 then return string.format("%.4g", result / count) else return tostring(0) end end return p