Facebook Pixel

findMaxNumber

JavaScript
easy

Write a function findMaxNumber that takes an array of numbers as input and returns the largest number in the array. If the array is empty, return null.

Example Inputs & Outputs

findMaxNumber([1, 2, 3, 4, 5]) // → 5 findMaxNumber([-10, -20, -3, -1]) // → -1 findMaxNumber([42]) // → 42 findMaxNumber([]) // → null findMaxNumber([100, 100, 100]) // → 100

Constraints & Edge Cases

  • Input is always an array.
  • Array can include positive, negative, and zero values.
  • Array can be empty — in that case, return null.
  • Array may include duplicate values.
  • Must not mutate the original array.

Solve Similar questions 🔥