The goal is to get the highest value in an array. I hope someone could walk me through where I went wrong with my code, and how I can get it to work.

What I am trying to accomplish is starting with a preset array, comparing `Arr[i]`

and `Arr[i+1]`

, then `Arr[i+1]`

and `Arr[i+2]`

and so on... pushing the highest value of each into an empty array called `Arrl`

. Then set Arr equal to `Arrl`

. Then calling the function back, and repeating until only `Arr[0]`

is left and display the result.

This is the code I have so far:

```
var Arr=[10,56,76,98,82,45,98];
function largernumber(Arr){
var Arrl=[];
while (Arr.length>1);
for (i=0; i<Arr.length; i++){
if(Arr[i]>Arr[i+1] || Arr[i]===Arr[i+1]){
Arrl.push(Arr[i]);
}
else{
ArrL.push(Arr[i+1]);
}
console.log(Arrl);
}
for(var ar=0 ; ar<Arrl.length ; ar++){
Arr[ar]=Arrl[ar];
}
return largernummber(Arr);
}
```

I am not great at describing so I will try to show what my plan is.
`var Arr=[10,56,76,98,82,45,98]`

(after each pass through the array length will decrease by one)

1st pass-through
`var Arr=[60,76,98,98,82,98]`

2nd
`var Arr=[76,98,98,98,98]`

3rd
`var Arr=[98,98,98,98]`

nth..
`var Arr=[98]`

Currently my logic is so flawed, its freezing the browser. oops... if possible I'd also love to see where I can place the console log to see each iteration.

While all the other answers have pointed out perfectly correct and actually simpler solutions to your problem, I'm just "fixing" your code to use the algorithm that you've mentioned. I've avoided any changes to your code that are unnecessary.

Aside from typos in variable names, these are the issues with the code as it is:

`while (Arr.length > 1);`

just loops forever. I assume it was an attempt to find the base case of the recursion. It should be`if (Arr.length === 1) return Arr[0];`

, which says "if there is only one element left, that is the largest and return it".`i + 1`

th element in an array, always be careful about accessing the last element. In your case, your loop goes till`i < Arr.length`

and`i + 1 === Arr.length`

for the last iteration which results in`undefined`

. Comparing numbers with`undefined`

won't work. So make sure you loop till the last but one element, using`Arr.length - 1`

.`return largernumber(Arr);`

to`return largernumber(Arrl);`

As you might have noticed by now, point 1 and 3 point out the places where there is infinite recursion.