We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Grading Students
Grading Students
Sort by
recency
|
4006 Discussions
|
Please Login in order to post a comment
I tested my solution in VSCode and results are correct, but i cannot submit as I get message the results are wrong. Could you check please?
function gradingStudents( grades ) {
const rounded = []; const gradesOnly = [...grades]; gradesOnly.shift(); for( let grade of gradesOnly ) if( grade < 38 || grade % 5 === 0 ) rounded.push(grade); else if( Math.floor(grade / 5) * 5 + 5 - grade < 3) rounded.push(Math.floor(grade / 5) * 5 + 5); else rounded.push(grade); return rounded;
}
I confess that, at first, I tried to round the value directly, but then I remembered that
Math.ceil
only works forfloats
, so:Divide the number by the
multiple (5)
:value / 5 = X
Since we're rounding up, we'll round it to the next whole number, which is Y.
Now, multiply Y by
multiple (5)
to find the nearestmultiple of 5
that's greater than the "value"This is my solution, how are things?
vector gradingStudents(vector grades) { for(int i = 0; i < grades.size(); i++){
} return grades; }
There is an issue with the question. It assumes the input to have the first element as the number of students (not a grade). However, my code only worked when considering the first element (grades[0] in python)..
Code
def complement(x, m): return (m - (x % m)) % m
def gradingStudents(grades): result = [] # Create a new list instead of modifying
grades
Here is my solution in python:
Write your code here