Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Find the Maximum

Working With Arrayseasy

Course · Section 11: Working With Arrays · Lecture 149: Simple Array Methods

Implement `findMax(arr)` that returns the largest number in `arr`. You may assume `arr` is non-empty.

Sample tests

Input: findMax([3,1,4,1,5,9])
Output: 9
Input: findMax([-1,-5,-2])
Output: -1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Math.max() with no arguments returns -Infinity.

Learning resources

  • MDN: Math.max
Approach & explanation (try first)

Spreading the array into Math.max yields its maximum.

Loading...
⌘/Ctrl + Enter

Run your code to see results.