Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Markdown · 932 B · at 2cc04ee

Write movingAverage(values, window) for a time series where some readings are missing.

  • values is a list where each element is either a number (a present reading) or absent (no reading).
  • window is 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" } when window is not a positive integer.
  • { kind: "not_finite", index } when a present reading is NaN, Infinity or -Infinity; index is the position of the first such reading.

The input list must not be modified.