Write movingAverage(values, window) for a time series where some readings are missing.
valuesis a list where each element is either a number (a present reading) or absent (no reading).windowis the window size.
Return a list with the same length as values. Element i is the arithmetic mean of the present readings among values[i - window + 1] through values[i] inclusive (near the start, only the indices that exist, starting from 0). Divide by the number of present readings in that range, not by window. If the range has no present readings, element i is absent.
Every present reading counts, whatever its value.
Failures, checked in this order:
{ kind: "invalid_window" }whenwindowis not a positive integer.{ kind: "not_finite", index }when a present reading isNaN,Infinityor-Infinity;indexis the position of the first such reading.
The input list must not be modified.