Averages/Simple moving average: Difference between revisions
Content added Content deleted
m (→{{header|D}}: Readability) |
|||
Line 656: | Line 656: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{incorrect|Lua|The algorithm used fails to solve the task. If you need help then read another languages entry or I could expand on what I added in the talk page.}} |
|||
<lang lua>do |
<lang lua>do |
||
local |
local t = {} |
||
function average(n) |
function average(n) |
||
if |
if #t == 10 then table.remove(t, 1) end |
||
t[#t + 1] = n |
|||
return |
return loadstring('return '..table.concat(t,'+'))() / #t |
||
end |
end |
||
end |
end |