Dev Helpers
← Back

Above-average selection

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

Open this example in the interactive library

Live preview

Source code

// components/AboveAverageSelection.tsx

export default function AboveAverageSelection({
  values = [2, 3, 3, 6, 11],
}: { values?: number[] } = {}) {
  const avg = values.reduce((a, b) => a + b, 0) / (values.length || 1);
  return <p>Above mean: {values.filter((v) => v > avg).join(", ") || "None"}</p>;
}