CHALLENGE 2: Type Safety with Arrays ==================================== SOLUTION: function calculateAverage(scores: number[]): number { const sum = scores.reduce((total, score) => total + score, 0); return sum / scores.length; } // Testing: const studentScores: number[] = [95, 87, 92, 88, 90]; const average = calculateAverage(studentScores); console.log(average); // Output: 90.4 EXPLANATION: - "scores: number[]" — parameter accepts an array of numbers - ": number" (after closing paren) — function returns a number - The reduce() method sums all values - Dividing by length gives the average ALTERNATIVE SOLUTION (simpler): function calculateAverage(scores: number[]): number { if (scores.length === 0) return 0; const sum = scores.reduce((a, b) => a + b, 0); return sum / scores.length; } WHY TYPE ANNOTATIONS MATTER HERE: - TypeScript ensures only numbers are passed - calculateAverage([95, 87, 92]) ✅ Works - calculateAverage([95, "87", 92]) ❌ Error! "87" is a string, not a number - The IDE knows the function returns a number, so the caller knows what to expect EDGE CASES: - Empty array: returns 0 (handled by the if check in alternative) - Single element: returns that element - Negative numbers: works fine