Skip to content

Commit bcaf9e8

Browse files
Merge pull request #87 from wakidurrahman/feat/problem-solving-012
feat: grading
2 parents f51faf6 + 642f9d3 commit bcaf9e8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/hackerrank/problem-solving/algorithms-011-020.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,28 @@ function timeConversion(s) {
2929

3030
return `${hours}:${minutes}:${seconds}`;
3131
}
32+
33+
/**
34+
* 012: HackerLand University has the following grading policy:
35+
*
36+
* Every student receives a grade in the inclusive range from 0 to 100.
37+
* Any grade less than 40 is a failing grade.
38+
*
39+
* Sam is a professor at the university and likes to round each student's grade according to these rules:
40+
* 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.
41+
* If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.
42+
*/
43+
44+
function gradingStudents(grades) {
45+
let count = [];
46+
for (let i = 0; i < grades.length; i++) {
47+
if (grades[i] % 5 == 3 && grades[i] >= 38) {
48+
count.push(grades[i] + 2);
49+
} else if (grades[i] % 5 == 4 && grades[i] >= 38) {
50+
count.push(grades[i] + 1);
51+
} else {
52+
count.push(grades[i]);
53+
}
54+
}
55+
return count;
56+
}

0 commit comments

Comments
 (0)