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:
@@ -90,6 +90,7 @@ function tableshuffle( t )
|
|||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
table.shuffle = tableshuffle
|
||||||
|
|
||||||
function tableslice( t, num )
|
function tableslice( t, num )
|
||||||
local ret = { }
|
local ret = { }
|
||||||
@@ -98,6 +99,30 @@ function tableslice( t, num )
|
|||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
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)
|
function round(val, decimal)
|
||||||
if (decimal) then
|
if (decimal) then
|
||||||
|
|||||||
Reference in New Issue
Block a user