Learn Lua · Numbers and text · Lesson 2 of 4

Statistics

The stats library summarises a list of numbers:

LUA
local minutes = { 4, 8, 15, 16, 23, 42 }
stats.mean(minutes)    --> 18.0
stats.median(minutes)  --> 15.5
stats.max(minutes)     --> 42

The 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.

LUA
input = { minutes = { 10, 20, 30, 60 } }

Steps

  1. Return mean: the average of input.minutes.
  2. Add median: their median.
  3. 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.