Sequence NODE_143
EasyFind Maximum in an Array
JavaScript
Technical Specification
Return the maximum number from a given non-empty array of numbers.
Input/Output Samples
Input:[1, 5, 3, 9, 2]
Output:9
Input:[-3, -10, -2]
Output:-2
Optimal Logic Path
function findMax(arr) {
return Math.max(...arr);
}Architectural Deep-Dive
Math.max accepts separate arguments, so using the spread operator we can easily get the largest value from the array.