-
addition of 2 vectors (javascript)
Hello,
is there a javascript method to add two arrays of numbers (something like Array.add(array)) or does one have to always write a loop ?
The problem i encountered is the following:
if V1 and V2 are arrays of numbers of the same length, to make their sum one can simply write: sum = V1+V2, but if the common length is >1000, then sum is an array of length 1000 (it took me ages to realize this…lost so much time), the remaining entries are not calculated. For instance, if POLO is an array of length 1300 whose entries are all equal to 1, then all entries of POLO+POLO are equal to 2, but POLO+POLO has length …1000, not 1300.If instead of writing sum = V1+V2 one explicitely writes:
for (k=0; k < V1.length; k++)
{
sum[k] = V1[k]+V2[k];
}
then sum has the correct length.
Really weird, and very well hidden feature. Is there a reason why it is so ?