Your function works correctly even if it can be reduced to
return input.slice().reverse();
//This will show that pointOrigins2 is not an independent copy of pointOrigins1 //When pointOrigins2 is modified pointOrigins1 is also being modified pointOrigins2[0].index++;
No. You do not change the pointOrigins2 array here, you access it and change the point object - the same point as in the pointOrigins1 array. However, pointOrigins1 !== pointOrigins2 .
You can change the array independent of another, for example. as
pointOrigins2[0] = { positionx: pointOrigins2[0].positionx, positiony: pointOrigins2[0].positiony, index: pointOrigins2[0].index + 1 };
and pointOrigins1 will remain untouched. Therefore, if you want to have points whose properties you can change without reflection elsewhere, you will need to create new points.
Bergi May 14 '14 at 23:21 2014-05-14 23:21
source share