I'd like to populate the parameters/values needed for this function, using table.concat(mytable, ", ") but no matter which way I try I’m not able to alter the string of numbers returned so it’s suitable for this function? Can anyone help ?
local function min_mean_max(...)
local min = select(1, ...)
local max = select(1, ...)
local mean = 0
-- Iterate using the numbers, no need the index variable use `_` as a placeholder
for _, number in ipairs({...}) do
-- Set a new minimum if necessary
if min > number then min = number end
-- Set a new maximum if necessary
if max < number then max = number end
-- Sum the numbers to find the average
mean = mean + number
end
-- Divide the numbers by their quantity
mean = mean / #{...}
return min, mean, max
end
For reference this works..
local min, mean, max = min_mean_max(961, 335, 342, 453, 601, 767, 889, 936)
print("Minimum, mean and maximum numbers are", min, mean, max)
I either need a different way to convert a table/array {961, 335, 342, 453, 601, 767, 889, 936} or convert a string like this “961, 335, 342, 453, 601, 767, 889, 936” ?
Or perhaps there is another route ?