MudkipTheEpic

Math API

Jan 16th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. function getAverage(table)
  2. local h
  3. local r
  4. h = 0
  5. for i=1, #table do
  6. r = tonumber(table[i])
  7. if r == nil then
  8. error("Table had non-numerical index")
  9. return nil
  10. end
  11. h = h + r
  12. end
  13. h = h / #table
  14. return h
  15. end
  16. function getFactors(num)
  17. local factors = {}
  18. local lol = tonumber(num)
  19. if lol == nil then
  20. error("Number expected: got "..type(num))
  21. return false
  22. end
  23. num = lol
  24. for i=1, num do
  25. if num % i == 0 then
  26. table.insert(factors, i)
  27. end
  28. end
  29. return factors
  30. end
Advertisement
Add Comment
Please, Sign In to add comment