+ 1
javascript code
I don't understand the result of this code. can you help me, please? var data=[21,2,70]; var vect=[10,20,30]; for(var i=0; i<=data.length; i++) { for(var j=i; j>=0; j--){ vect[j]+=data[j]; } } console.log(vect);
1 Odpowiedź
+ 4
what this code does is, it sums the data onto the vect, and the index of the element states how often it gets summed
(the first index always gets summed the most and the last index always gets summed once).
in this example it is:
10+ 21 x3 =73
20+ 2 x2 =24
30+ 70 x1 =100
so in the console [73, 24, 100] is printed
I don't know what it is used for, but this is what it does
here I have the code (which I corrected, because it should've been i<data.length and not <=
https://code.sololearn.com/WXRIKtup4yD2/?ref=app