simple-statistics
Version:
16 lines (14 loc) • 411 B
JavaScript
/**
* 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.
*
* @param {Array<number>} x input
* @returns {number} maximum value
* @example
* maxSorted([-100, -10, 1, 2, 5]); // => 5
*/
function maxSorted(x) {
return x[x.length - 1];
}
export default maxSorted;