Skip to content

DRY: single clamp() util (identical body copy-pasted across 4 files + 2 inline) #382

Description

@NesiciCoding

Over-engineering / DRY (ponytail-audit finding)

clamp(value, min, max) has an identical body — Math.min(max, Math.max(min, value)) — copy-pasted across four modules, plus two more inline variants.

Duplicated in

  • src/utils/testCalc.ts
  • src/pages/TestResultsPage.tsx
  • src/utils/placementRouting.ts
  • src/utils/testSummaryAggregator.ts
  • inline variants: src/pages/GradeStudent.tsx (line 73), src/pages/TestBuilderPage.tsx (clampThresholdPct, line 39)

Fix

Add src/utils/clamp.ts with a single exported clamp, import it in the four files, and drop the local copies. Fold the two inline variants in where they match. Net ~-18 lines.

Scope: complexity cleanup only, not a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions