JavaScript has no built-in function for finding the lowest value in an array, so the most efficient approach is a custom method that iterates through the array, comparing values to identify the lowest.
function myArrayMin(arr) { let len = arr.length; let min = Infinity; while (len–) { if (arr[len] < min) { min = arr[len]; } } return min; } |
JavaScript lacks a built-in function to find the highest value in an array, so a custom method is used to iterate and compare values efficiently.
function myArrayMax(arr) { let len = arr.length; let max = –Infinity; while (len–) { if (arr[len] > max) { max = arr[len]; } } return max; } |