OneCompiler

FFIND MAX ELEMENT IN ARAAY

117

function findMax(arr) {

let max = arr[0]; // Initialize max with the first element of the array

for (let i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}

return max;
}

const arr=[3, 8, 1, 9, 5];
...