← All Exercises

Find Maximum Value

basicjavascript~10min

Background

Finding extremes is a core operation in data analysis, algorithm optimization, and game development.

Problem

Write a function that finds and returns the largest number in a given array of numbers. Return null for empty arrays.

Input

An array of numbers, potentially empty.

Output

The largest number in the array, or null if the array is empty.

Sample tests

Sample 1

Input: [3, 7, 2, 9, 1]
Expected: 9

Your solution

Learning objective

Learn to use Math.max with spread syntax and handle edge cases properly.