Skip to content

Commit 642f9d3

Browse files
author
wakidurrahman
committed
feat: grading
1 parent ef1b98d commit 642f9d3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,26 @@ function timeConversion(s) {
3131
}
3232

3333
/**
34-
* 012: grading
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.
3542
*/
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)