I have a problem in this piece of code. The results of console.log() statements are different but I have not changed the value of temp array. How can I solve this problem? Here is my code:
var i , j , temp, main,sum,numb=4;
temp=[1];
main=[];
sum=[];
for(i=1; i<=numb ; i++){
for(j=0 ; j<=i ; j++){
if(j==0||j==i){
main[j]=1;
}
else{
console.log(temp[j]+"*"+temp[j-1]);
main[j]=temp[j]+temp[j-1];
console.log(temp[j]+"**"+temp[j-1]);
}
}
sum.push(temp);
temp=main;
}