Dev Helpers
← Back

Moving average line

Import and render <MovingAverageLine /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/MovingAverageLine.tsx

export default function MovingAverageLine({
  values = [2, 3, 3, 6, 11],
}: { values?: number[] } = {}) {
  return (
    <ol>
      {values.slice(2).map((v, i) => (
        <li key={i}>{((values[i] + values[i + 1] + v) / 3).toFixed(2)}</li>
      ))}
    </ol>
  );
}