table sum, average, and standard deviation functions from shakesoda. (I also try to attempt to alias table.slice to tableslice and table.shuffle to tableshuffle)

This commit is contained in:
AJ Kelly
2010-08-05 23:23:47 -05:00
parent 8a0919872a
commit e4fc513c7e
+25
View File
@@ -90,6 +90,7 @@ function tableshuffle( t )
end
return ret
end
table.shuffle = tableshuffle
function tableslice( t, num )
local ret = { }
@@ -98,6 +99,30 @@ function tableslice( t, num )
end
return ret
end
table.slice = tableslice
-- add together the contents of a table
function table.sum( t )
local sum = 0
for i=1,#t do
sum = sum + t[i]
end
return sum
end
-- average of all table values
function table.average( t )
return table.sum( t ) / #t
end
-- furthest value from the average of a given table
function table.deviation( t )
local offset = math.abs(table.average(t))
for i=1,#t do
offset = math.max(math.abs(t[i]), offset)
end
return offset
end
function round(val, decimal)
if (decimal) then