Published
Edited
Sep 29, 2022
Importers
Insert cell
# Untitled
Insert cell
computeMovingAverages = (values, N) => {
let i = 0;
let sum = 0;
const means = new Float64Array(values.length).fill(0);
for (let n = Math.min(N - 1, values.length); i < n; ++i) {
sum += values[i];
}
for (let n = values.length; i < n; ++i) {
sum += values[i];
means[i] = sum / N;
sum -= values[i - N + 1];
}
return means;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more