DEV Community

AdmissionArena
AdmissionArena

Posted on Edited on

Weighted GPA vs Simple Average: A Small TypeScript Function and Why It Matters

When a university asks for your GPA, it almost never means the average of your course grades. It means a credit-weighted average, where a four-credit course counts more than a one-credit lab. The difference can be large, and it is a good example of a tiny function that is easy to get subtly wrong.

The formula

For each course, multiply grade points by credits. Add those up, then divide by the total credits:

GPA = sum(points x credits) / sum(credits)

A small implementation

type Course = { name: string; credits: number; points: number };

export function weightedGpa(courses: Course[]): number | null {
  const totalCredits = courses.reduce((sum, c) => sum + c.credits, 0);
  if (totalCredits === 0) return null; // nothing to average
  const qualityPoints = courses.reduce((sum, c) => sum + c.points * c.credits, 0);
  return Math.round((qualityPoints / totalCredits) * 100) / 100;
}
Enter fullscreen mode Exit fullscreen mode

Two details are worth noting. Guard against zero total credits so you never divide by zero, and round only at the very end so intermediate values stay exact.

Why not just average the grades?

Course Credits Points
Core module 4 3.5
Elective 3 3.0
Lab 1 2.0

The simple average of 3.5, 3.0 and 2.0 is 2.83. The weighted result is (4 x 3.5 + 3 x 3.0 + 1 x 2.0) / 8 = 25 / 8 = 3.13. The heavy core module pulls the result up, which is exactly how most universities and credential evaluators calculate it.

The part code cannot decide for you

The function above takes grade points as input. Converting a transcript from another grading system into those points is a separate decision, and it depends on the institution or evaluation service, not on simple proportions. Dividing a percentage by 25 is a common shortcut that often understates strong students. Treat any converted GPA as an estimate and confirm with the university's own guidance.

Trying it without code

If you want to experiment with your own courses and credits, the WES GPA Calculator gives a credit-weighted estimate, and the Admission Chance Calculator shows how a GPA fits typical requirements for different destinations.

Disclosure: We are AdmissionArena, which operates both tools linked above. They give estimates, not official evaluations.

Top comments (0)