I'm a newbie for javascript. I have two variable, one is Ax2 and the other is Ay2, they will be constantly updated, I want to get the average of their latest refreshed 10 profiles, so I tried this, but it didn't work, can anyone help me?
var Ax2 = 0
var Ay2 = 0
connection.on("ReceiveMessage", function (target) {
Ax2 = `${target} `
document.getElementById('Ax2').textContent = Ax2 ;
});
connection.on("ReceiveMessage2", function (target2) {
Ay2 = `${target2} ` * -1
document.getElementById('Ay2').textContent = Ay2 ;
});
let arr1 = new Array(10);
let arr2 = new Array(10);
function ArrayAvg1(arr1) {
var i = -1, summ = 0, ArrayLen1 = arr1.length;
while (i < ArrayLen1) {
arr1.push(Ax2)
summ = summ + arr1[i++];
}
return summ / ArrayLen1;
}
function ArrayAvg2(arr2) {
var i = -1, summ = 0, ArrayLen2 = arr2.length;
while (i < ArrayLen2) {
arr2.push(Ay2)
summ = summ + arr2[i++];
}
return summ / ArrayLen2;
}
var AX_after_correction = Ax2 - ArrayAvg1(arr1)
var AY_after_correction = Ay2 - ArrayAvg2(arr2)
var AX_after_correction = document.getElementById('AX_after_correction')
var AY_after_correction = document.getElementById('AY_after_correction')