• + 0 comments
    function gradingStudents(grades) {
        // less than 38 is automatically failed
        // if the difference b/w original marks and rounded original marks by closest multiple of 5
        // is less than 3, then round off to rounded marks. If not, original marks remain the same.
        let minMarks = 38;
        let lengthOfGrades = grades.length;
        let finalArray = [];
        let mult5 = 0;
        console.log(grades);
        // assuming grades -> [73,67,38,33]
        for(let i = 0; i < lengthOfGrades; i++ ){
            // fail because grades LT 38
            if( grades[i] < minMarks ){
                finalArray.push(grades[i]);
            }else {
                // grades are GTE 38
                // finding the multiples of 5
                mult5 = Math.ceil(grades[i]/5); // 73/5 => 14.6 => ceil(14.6) => 15
                mult5 *= 5; // to get the multiple of 5 closest to grade 15*5=>75
                if( mult5 - grades[i] < 3 ){
                    finalArray.push(mult5);
                }else{
                    finalArray.push(grades[i]);
                }
            }
        } 
        return finalArray;
    }
    

    ` undefined