1. Mean, min and max
Before training anything, look at your data. Three quick summaries of a column:
- mean (average): add everything, divide by how many
- min: the smallest value
- max: the largest value
They catch mistakes early. If the max weight of a mango is 9000 g, someone typed an extra zero!
To find the max, start with the first value and walk through the rest, keeping the biggest you have seen.
const marks = [62, 75, 48, 90];
let total = 0;
for (const m of marks) total += m;
console.log("mean", total / marks.length);
Challenge: Report-card summary
Write three functions that take an array of numbers:
mean(xs)returns the averageminOf(xs)returns the smallest valuemaxOf(xs)returns the largest value
You may use a loop or Math.min(...xs). Arrays will never be empty.