I'm confused. I have an array myArray = [2, 2, 2, 1, 1] and without knowing, it takes the values of the Array testArray.
if(count == 5) {
alert("beginn" + myArray[2]);
var testArray=testFunction(myArray);
alert("middle" + myArray[2]);
var testCount=countNumber(testArray);
if (testCount = 3){
count = 4;
}
}
And here is the function:
function testFunction(testArray){
var minimum=Math.min.apply(Math,testArray);
var i=0;
var position=-1;
for(i;i<testArray.length;i++){
if(position==-1){
if(minimum==testArray[i]){
position=i;
}
}
}
i = 0;
for(i; i < testArray.length; i++){
if(i != position){
testArray[i] = testArray[i] - 1;
}
}
return testArray;
}
So after the function testArray is correctly [1,1,1,1,0], but unfortunately also myArray and I don't know why.
var testArray = testFunction(myArray.slice());, also, indent your code. (=if (testCount == 3)