Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Summary Stats

Derived Statemedium

Course · Section 11: Working With Arrays · Lecture 160: The reduce Method

Implement `summaryStats(nums)` returning `{ min, max, avg }` for a non-empty array of numbers.

Sample tests

Input: summaryStats([1,2,3,4])
Output: {"min":1,"max":4,"avg":2.5}
Input: summaryStats([5])
Output: {"min":5,"max":5,"avg":5}

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Spreading a very large array into Math.min/max can overflow the call stack; reduce is safer at scale.

Learning resources

  • React: Choosing the State Structure
Approach & explanation (try first)

Derive the summary in one pass: Math.min/max for the bounds and a reduce-based mean, returned together as { min, max, avg }.

Loading...
⌘/Ctrl + Enter

Run your code to see results.