I am attempting to iterate through a large array of values and calculate the average of one of the values for each second. I seem to be having trouble getting this code to function correctly, and it appears that the issue lies within the nested while loop. Could it be possible that I made a scope error preventing me from iterating the for loop index?
The data contains timestamps in milliseconds and radiation counts.
a.data[i][0]
represents the timestamp and a.data[i][26]
represents the count.
for (i = 0; i < a.data.length; i++){
// counts is the count of radiation over the last timeframe
var counts = 0;
// t1 is the start time
// t2 is the current iteration time
var t1, t2 = a.data[i][0];
while ((t2 - t1) < 1000){
t2 = a.data[i][0];
counts += a.data[i][26];
i++;
}
// Geiger Data is an array of { x:(time), y:(value)} datapoints.
GeigerData.push({x: (t1/1000), y: counts});
}