Grading Students

  • + 0 comments

    My Typescript solution:

    function gradingStudents(grades: number[]): number[] {
        const roundedGrades: number[] = [];
        const length = grades.length;
        
        for (let i = 0; i < length; i++) {
            const grade = grades[i];
            const nextMultipleOf5 = grades[i] + (5 - (grades[i] % 5));
            if (grade < 38) {
                roundedGrades.push(grade);
            } else if (nextMultipleOf5 - grade < 3) {
                roundedGrades.push(nextMultipleOf5);
            } else {
                roundedGrades.push(grade);
            }
        }
        
        return roundedGrades;
    }