You are viewing a single comment's thread. Return to all comments →
I confess that, at first, I tried to round the value directly, but then I remembered that Math.ceil only works for floats, so:
Math.ceil
floats
Divide the number by the multiple (5):
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 nearest multiple of 5 that's greater than the "value"
multiple of 5
function gradingStudents(grades: number[]): number[] { const response = grades.reduce((acc, value, index) => { const next = Math.ceil(value / 5) * 5; const factor = Math.abs(next - value); acc[index] = value; if (factor < 3 && value >= 38) { acc[index] = next; } return acc; }, [] as number[]); return response; }
Seems like cookies are disabled on this browser, please enable them to open this website
Grading Students
You are viewing a single comment's thread. Return to all comments →
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"