javascriptbeginner10 minutes
Find the Largest Number in an Array
Write a function to identify the largest number within an array of integers.
Challenge prompt
Create a function named findLargestNumber that accepts an array of integers and returns the largest number in the array. If the array is empty, return null.
Guidance
- • Consider looping through the array to compare each number.
- • Use a variable to keep track of the current largest number found.
Hints
- • Initialize the largest number variable to the first element of the array.
- • Remember to check if the array is empty before processing.
Starter code
function findLargestNumber(numbers) {
// Your code here
}Expected output
findLargestNumber([3, 5, 7, 2, 8]) // 8 findLargestNumber([]) // null
Core concepts
arraysloopsconditionalsfunctions
Challenge a Friend
Send this duel to someone else and see if they can solve it.