Skip to content

feat: grading #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/hackerrank/problem-solving/algorithms-011-020.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ function timeConversion(s) {

return `${hours}:${minutes}:${seconds}`;
}

/**
* 012: HackerLand University has the following grading policy:
*
* Every student receives a grade in the inclusive range from 0 to 100.
* Any grade less than 40 is a failing grade.
*
* Sam is a professor at the university and likes to round each student's grade according to these rules:
* If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
* If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.
*/

function gradingStudents(grades) {
let count = [];
for (let i = 0; i < grades.length; i++) {
if (grades[i] % 5 == 3 && grades[i] >= 38) {
count.push(grades[i] + 2);
} else if (grades[i] % 5 == 4 && grades[i] >= 38) {
count.push(grades[i] + 1);
} else {
count.push(grades[i]);
}
}
return count;
}