Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

lua calculate average number

function math.average(t)
  local sum = 0
  for _,v in pairs(t) do -- Get the sum of all numbers in t
    sum = sum + v
  end
  return sum / #t
end

print(math.average({9, 10, 12, 13, 13, 13, 15, 15, 16, 16, 18, 22, 23, 24, 24, 25})) -- Result: 16.75
 
PREVIOUS NEXT
Tagged: #lua #calculate #average #number
ADD COMMENT
Topic
Name
7+3 =