Averages and Weighted Averages
Computing simple averages, tracking how an average shifts when a value is added or removed, and computing weighted averages.
What you'll learn
- Compute a simple average from a list of values, and the total from a known average and count
- Determine a group's new average after a value is added to it
- Compute a weighted average when different values carry different weights
Prerequisites
Explanation
A simple average (arithmetic mean) of a set of values is their total divided by how many values there are: average = sum / count. This also runs backward usefully — if you know the average and the count, the sum is just average × count. If a problem tells you "the average of 4 numbers is 18," you immediately know their total is 4 × 18 = 72, even without knowing any individual number.
Effect of adding or removing a value. A common question type gives you a group's current average and asks what happens when one more value joins (or one leaves). The trick is always to work through the sum, never try to average the averages directly:
Worked example. The average weight of 9 students is 45 kg. A tenth student weighing 55 kg joins the group. What's the new average? First recover the old total: 9 × 45 = 405 kg. Add the new student: 405 + 55 = 460 kg. Divide by the new count: 460 / 10 = 46 kg. Notice the new average moved up from 45 toward 55 — because the joining student is heavier than the existing average, they pull the average up, but only by a fraction of the gap (not all the way to 55), since they're just one value among ten.
Weighted averages apply when different values don't contribute equally — some values represent bigger groups or matter more, and need to be weighted accordingly. The formula: weighted average = (Σ value × weight) / (Σ weight), where Σ means "sum of."
Worked example. A class of 30 students averages 70 marks, and a second class of 20 students averages 80 marks. What's the combined average across both classes? It is not simply (70+80)/2 = 75, because the two classes have different sizes. Correctly weighting by class size: (30×70 + 20×80) / (30+20) = (2100 + 1600) / 50 = 3700/50 = 74. That's closer to 70 than to 80, correctly reflecting that the larger, lower-scoring class of 30 pulls the combined average down more than the smaller class of 20 pulls it up.
A closely related, easy-to-miss weighted average shows up in time-weighted average speed: if you drive part of a trip at one speed for a certain time and the rest at another speed for a different time, the average speed for the whole trip is the total distance covered divided by the total time taken — which is mathematically a weighted average of the two speeds, weighted by time spent at each. (This is a different formula from the equal-distance harmonic-mean case from the time-speed-distance lesson — the correct approach depends on whether time or distance is what's held equal.)
Example
A weighted average multiplies each value by its weight before dividing by the total weight.
function weightedAverage(values, weights) {
const totalWeight = weights.reduce((a, b) => a + b, 0);
const weightedSum = values.reduce((sum, v, i) => sum + v * weights[i], 0);
return Math.round((weightedSum / totalWeight) * 100) / 100;
}
// Example: weightedAverage([70, 80], [30, 20]) -> 74Guided exercise
Guided exercise
Write newAverageAfterAdding(oldAverage, oldCount, newValue) that returns the new average, rounded to 2 decimal places, after one additional value newValue is added to a group that previously had oldCount values averaging oldAverage.
Checks: Computes the new average after adding a higher value · Computes the new average starting from a zero average · plus 1 hidden check
Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.
Stuck? Get a hint.
Independent exercise
Independent exercise
Write weightedAverage(values, weights) where values and weights are same-length arrays. Return the weighted average, rounded to 2 decimal places, as (sum of value*weight for each pair) divided by (sum of weights).
Checks: Computes a two-group weighted average · Computes a three-value weighted average with uneven weights · plus 1 hidden check
Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.
Stuck? Get a hint.
Common mistakes
- Averaging group averages directly (like (70+80)/2) instead of weighting by each group's size, which only gives the right answer when the groups happen to be equal size.
- Forgetting to recover the total (average x count) before adding or removing a value, and instead trying to adjust the average number directly.
- Treating 'average speed over time' and 'average speed over distance' as the same calculation -- they use different weighting and generally give different answers.
Knowledge check
Takeaway
Never average averages directly -- recover the underlying totals (or use explicit weights) first, then divide once at the end.
Summary
A simple average is sum divided by count, and this reverses cleanly to recover a sum from a known average and count. Adding or removing a value requires working through the total, not the average number itself. Weighted averages multiply each value by its own weight before dividing by total weight, which correctly reflects that not every value should count equally.
Your notes
Notes save automatically.
Finished this lesson?
Mark it complete to track your progress and schedule a future review.
AI tutor
The optional AI tutor isn't enabled in this deployment. All lessons, exercises, quizzes, and search work fully without it.