• + 0 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:

    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 nearest multiple of 5 that's greater than the "value"

    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;
    }