UNPKG

ects-oleksandr-sokhan

Version:

Converter scores from the 100-point grading system to the ECTS

35 lines (29 loc) 895 B
class ECTS { #gradeRanges = [ { min: 90, max: 100, grade: 'A' }, { min: 82, max: 89, grade: 'B' }, { min: 74, max: 81, grade: 'C' }, { min: 65, max: 73, grade: 'D' }, { min: 60, max: 64, grade: 'E' }, { min: 0, max: 59, grade: 'F' } ]; constructor(score) { if (!ECTS.isValidScore(score)) { throw new Error('Score must be a number between 0 and 100'); } this.score = score; } ectsFromScore() { const grade = this.#gradeRanges.find(range => this.score >= range.min && this.score <= range.max ); return grade ? grade.grade : 'Invalid score'; } getGradeRanges() { return [...this.#gradeRanges]; } static isValidScore(score) { return typeof score === 'number' && score >= 0 && score <= 100; } } module.exports = ECTS;