I trying to push an array I've generated to a multidimensional array, and for some reason the value of all the other positions in the array's values, are the same as the value I just pushed.
For example: I do
var grades = [];
for(var i = 0; i < num_qes + 1; i++){
var grade = [0, 0, 0, 0];
grade[0] = i;
for(var n = 0; n < num_qes+ 1; n++){
grade[1] = n;
for(var f = 0; f < num_qes+ 1; f++){
grade[2] = f;
for(var t = 0; t < num_qes+ 1; t++){
grade[3] = t;
allGrad = grade[0] + grade[1] + grade[2] + grade[3];
//println(allGrad);
if(allGrad === num_qes){
grades.push(grade);
}
}
}
}
Here at the end I check to see if all of the values in my generated array are exactly equal to the number of questions.
if(allGrad === num_qes){
grades.push(grade);
}
Let's say that grade = [9, 1, 0, 0], when I push this value to the multidimensional array, grades, all the values change to [9, 1, 0, 0]. So the multidimensional array looks like this: [[9, 1, 0, 0], [9, 1, 0, 0], [9, 1, 0, 0]], when it SHOULD look like this: [[9, 0, 0, 1], [9, 0, 1, 0], [9, 1, 0, 0]].
I hope what I said make senses, and thanks in advance for ansnewing.
The jsfiddle is right here