export function calculateRollingAverage(data, windowSize) { | |
let rollingAvg = []; | |
for (let i = 0; i < data.length; i++) { | |
if (i < windowSize - 1) { | |
rollingAvg.push(null); // Not enough data points to calculate average | |
} else { | |
let sum = 0; | |
for (let j = 0; j < windowSize; j++) { | |
sum += data[i - j]; | |
} | |
rollingAvg.push(sum / windowSize); | |
} | |
} | |
return rollingAvg; | |
} |