Beginner
Find the Largest Number in an Array
Description
Your task is to write a function that takes an array of numbers as input and returns the largest number in the array.
Finding the maximum value in a dataset is a common operation in many real-world applications, such as:
- Determining the highest score in a game.
- Analyzing data trends, such as peak website traffic.
- Identifying extreme values in scientific experiments or financial reports.
Requirements
Input: An array containing at least one number (positive, negative, or a mix).
Output: A single number representing the largest value in the array.
Considerations:
- The function should correctly handle negative numbers and mixed values.
- Arrays will always contain at least one number, so handling empty arrays is not necessary.
- The function should work efficiently for large datasets.
Example Usage
findLargestNumber([3, 7, 2, 9, 5]);// Expected output: 9findLargestNumber([-10, -3, -45, -1]);// Expected output: -1findLargestNumber([100]);// Expected output: 100findLargestNumber([-2, 0, 8, -1]);// Expected output: 8
Did you know?
The first-ever website was created by Tim Berners-Lee for the internet.
Test Cases
Input:
[ 3, 1, 7, 4, 9, 2 ]
Expected Output:
9