To create a loop with a special condition?

There is an array c2 of length length, it is necessary to sum the works sum2=c2[j]*c2[j+2m], and j+2m does not exceed the length and >=0 that part of the code:
var sum2=0;
for(var j=0;j<c2.length;j++) { for(var m="0;m<(c2.length-1)/2,j+2*m<c2.length;m++)" sum2+="c2[j]*c2[j+2*m];" document.write("value of c2:"+(j+2*m)+ "<br>");
}
 document.write("Value coeff c2:"+c2[j]+ "<br>");
}
document.write("Value coeff c2 sum2:"+sum2+ "<br>");</c2.length;j++)>

In the inner loop are summarized, not all of the elements such as negative j+2*m
June 10th 19 at 14:45
2 answers
June 10th 19 at 14:47
Solution
Here is the answer and the complete code of the program
the <script>
var c2=[],c3=[],c4=[],c5=[];
alert(new Date());
c2[0] = 0.4829629131445341;
c2[1] = 0.8365163037378077;
c2[2] = 0.2241438680420134;
c2[3] = -0.1294095225512603;
c3[0] = 0.3326705529500825;
c3[1] = 0.8068915093110924;
c3[2] = 0.4598775021184914;
c3[3] = -0.1350110200102546;
c3[4] = -0.0854412738820267;
c3[5] = 0.0352262918857095;
c4[0] = 0.2303778133088964;
c4[1] = 0.7148465705529154;
c4[2] = 0.6308807679398587;
c4[3] = -0.0279837694168599;
c4[4] = -0.1870348117190931;
c4[5] = 0.0308413818355607;
c4[6] = 0.0328830116668852;
c4[7] = -0.0105974017850690;
c5[0] = 0.1601023979741929;
c5[1] = 0.6038292697971895;
c5[2] = 0.7243085284377726;
c5[3] = 0.1384281459013203;
c5[4] = -0.2422948870663823;
c5[5] = -0.0322448695846381;
c5[6] = 0.0775714938400459;
c5[7] = -0.0062414902127983;
c5[8] = -0.0125807519990820;
c5[9] = 0.0033357252854738;
var sum=0,sum2=0;
for(var j=0;j<c2.length;j++)
{
sum+=c2[j]*Math.sqrt(2);
 for(var m=Math.round(-(c2.length-1)/2);m<(c2.length-1)/2,j+2*m<c2.length;m++)
{
if(j+2*m>=0)
 { 
sum2+=2*c2[j]*c2[j+2*m];
 document.write("Value of c2:"+(j+2*m)+ "<br>");
}
}
 document.write("Value coeff c2:"+c2[j]+ "<br>");
}
document.write("Value of c2 coefficients of the polynomial sum:"+sum+ "<br>");
document.write("Value coeff c2 sum2:"+sum2+ "<br>");
sum=0,sum2=0;;
for(var j=0;j<c3.length;j++)
{
sum+=c3[j]*Math.sqrt(2);
 document.write("Value coeff c3:"+c3[j]+ "<br>");
 for(var m=Math.round(-(c3.length-1)/2);m<(c3.length-1)/2,j+2*m<c3.length;m++)
{
if(j+2*m>=0)
 { 
sum2+=2*c3[j]*c3[j+2*m];
 document.write("c3 Value:"+(j+2*m)+ "<br>");
}
}
}
document.write("Value of the c3 coeff sum:"+sum+ "<br>");
document.write("Value coeff c3 sum2:"+sum2+ "<br>");
sum=0,sum2=0;
for(var j=0;j<c4.length;j++)
{
sum+=c4[j]*Math.sqrt(2);
 document.write("Value coeff c4:"+c4[j]+ "<br>");
 for(var m=Math.round(-(c4.length-1)/2);m<(c4.length-1)/2,j+2*m<c4.length;m++)
{
if(j+2*m>=0)
 { 
sum2+=2*c4[j]*c4[j+2*m];
 document.write("Value: c4:"+(j+2*m)+ "<br>");
}
}
}
document.write("Value of c4 coeff sum:"+sum+ "<br>");
document.write("Value of c4 coeff sum2:"+sum2+ "<br>");
sum=0,sum2=0;;
for(var j=0;j<c5.length;j++)
{
sum+=c5[j]*Math.sqrt(2);
 document.write("Value c5 coeff:"+c5[j]+ "<br>");
 for(var m=Math.round(-(c5.length-1)/2);m<(c5.length-1)/2,j+2*m<c5.length;m++)
{
if(j+2*m>=0)
 { 
sum2+=2*c5[j]*c5[j+2*m];
 document.write("Value c5:"+(j+2*m)+ "<br>");
}
}
}
document.write("Value c5 coeff sum:"+sum+ "<br>");
document.write("Value coeff c5 sum2:"+sum2+ "<br>");
console.log("echo");
</script>
June 10th 19 at 14:49
Simply need to be:
for(var j=0;j<c2.length;j++) { for(var m="j;m<c2.length;m+=2)" sum2+="c2[j]*c2[m];" document.write("value of c2:"+c2[m]+ "<br>");
}
 document.write("Value coeff c2:"+c2[j]+ "<br>");
}</c2.length;j++)>
But if we take j=2 and m=-2 in your cycle this does not work - joannie.Waelchi commented on June 10th 19 at 14:52

Find more questions by tags ProgrammingJavaScript