The Peak Score
MediumAcc. 91.8%
+25 XP 10
Leading Strategy
To find the maximum value, you compare each element against a "current leader" variable.
The Assignment
Your function receives an array scores.
- Initialize
maxwith the first element of the array (or a very small number). - Loop through the array starting from index 1.
- If the current score is greater than
max, updatemax. - Print the final
max.
01EXAMPLE 1
Input
scores = [5, 15, 8, 10]Output
15Explanation: 15 is the highest.
Constraints
- Do not use Math.max(...array).
- Handle the case where all numbers are negative.
ArraysLoopsSearch
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
scores[5,15,8]
Expected Output
15
Click RUN to test your solution