Skip to content

maxSorted

maxSorted(x): number

Defined in: src/max_sorted.js:12

The maximum is the highest number in the array. With a sorted array, the last element in the array is always the largest, so this calculation can be done in one step, or constant time.

number[]

input

number

maximum value

if x is empty

maxSorted([-100, -10, 1, 2, 5]); // => 5