I want to find the longest series of collatz sequence under 100 and this code outputs 2, which is not the answer. when i watch the variables, whenever the .push()function adds something to the testary it also adds to the maxary. Why is it adding a value to the end of both?
var n;
var m;
var testary = [];
var maxary = [];
var max;
for(i=2;i<100;i++){
n = i;
m = i;
while(n>1){
if(n%2 == 0){
testary.push(n);
n = n/2;
} else if(n%2 != 0){
testary.push(n);
n = (3*n)+1;
}
if(testary.length>maxary.length){
maxary = testary;
max = m;
}
}}