The function only reurn the greatest number if it is at first (arr[0]), or last index (arr[arr.length-1]) of the array. How do I fix the logical error?
function isGreater(arr) {
let a = arr[0];
for (let i = 0; i < arr.length; i++) {
var isGreat = (a < arr[i]) ? arr[i] : a;
}
return isGreat;
}
console.log(isGreater([7, 9, 10000, 11, 25, 20]));
// output=> 20, expected output 10000
console.log(isGreater([7, 11, 25, 2]));
// output=> 7, expected output 25