findMaxNumber
JavaScript
easy
15 mins
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 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
