Repair a misleading score summary

Debug edge cases and explain a correction

← All assignments

Assignment preview

This is the complete public sample: the brief, source notes, deliverables, checks, and review criteria below. Download the same materials to work offline. Confirmed paid assignment terms and submission tools are available only in the invited portal.

The brief

Repair a JavaScript function that summarizes assignment scores. Null represents unreviewed work and must be excluded. Zero is a valid score. Reject other invalid values and return null for an empty reviewed set.

Your source packet

Fictional source notes for this exercise. No outside client data.

Buggy function:
function average(scores) {
  const reviewed = scores.filter(Boolean);
  return reviewed.reduce((a, b) => a + b, 0) / scores.length;
}

Input [0, 80, null, 100] should return 60. Accept only finite numbers from 0 to 100 or null. Reject strings, undefined, NaN, and out-of-range numbers with an error. Inputs must not be mutated.

What to deliver

  1. The corrected function
  2. Tests for zero, null, empty arrays, all-null arrays, bad types, and out-of-range values
  3. A 200–300 word explanation of both original bugs

Check your understanding

  1. What does filter(Boolean) do to a score of zero?
  2. Which array length belongs in the denominator?

Request a beta invitation

Request early access