diff --git a/src/hackerrank/problem-solving/algorithms-011-020.js b/src/hackerrank/problem-solving/algorithms-011-020.js index 2c167db..11c334b 100644 --- a/src/hackerrank/problem-solving/algorithms-011-020.js +++ b/src/hackerrank/problem-solving/algorithms-011-020.js @@ -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; +}