티스토리 뷰

Algorithms

Grading Students

seoca 2020. 8. 22. 21:55

 

 

 

Solution in JavaScript

const grades = [73, 67, 38, 33];

function gradingStudents(grade) {
    for (let i = 0; i < grade.length; i++) {
        if (grade[i] >= 38) {
            if (grade[i] % 5 === 3) {
                grade[i] += 2
            } else if (grade[i] % 5 === 4) {
                grade[i] += 1
            }
        }
    }

    return grade;
}

console.log(gradingStudents(grades)); //[ 75, 67, 40, 33 ]

 

 

 

 

 Reference

https://www.hackerrank.com/challenges/grading/problem

 

Grading Students | HackerRank

Round student grades according to Sam's rules.

www.hackerrank.com

 

'Algorithms' 카테고리의 다른 글

Breaking the Records  (0) 2020.09.04
Apple and Orange  (0) 2020.08.24
Time Conversion  (0) 2020.08.22
Birthday Cake Candles  (0) 2020.08.16
Mini-Max Sum  (0) 2020.08.04