Learn Lua · Numbers and text · Lesson 2 of 4
Statistics
The stats library summarises a list of numbers:
local minutes = { 4, 8, 15, 16, 23, 42 }
stats.mean(minutes) --> 18.0
stats.median(minutes) --> 15.5
stats.max(minutes) --> 42The median is the middle value once the list is sorted (or the average of the two middle values). It's less pulled about by one unusual value than the mean.
What your code receives
Your code gets its data as input. The type Input line at the top of the code lists every field, and the editor uses it to suggest field names and spot typos. Here is an example. Each check sends different values, so work from the fields rather than these exact values.
input = { minutes = { 10, 20, 30, 60 } }Steps
- Return
mean: the average ofinput.minutes. - Add
median: their median. - Add
slowest: the largest.
Show a hint
Each field is one call to a stats function on the whole list. "Mean" is the usual
average.