Last active
September 8, 2022 09:47
-
-
Save Nasah-Kuma/d3ee40523767514e0608cb97788daf53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Complete the 'gradingStudents' function below. | |
* | |
* The function is expected to return an INTEGER_ARRAY. | |
* The function accepts INTEGER_ARRAY grades as parameter. | |
* https://www.hackerrank.com/challenges/grading/problem?isFullScreen=true | |
*/ | |
function gradingStudents(grades) { | |
// Write your code here | |
function findDiff(grade) { | |
const nextMultiple = grade + (5 - (grade % 5)); | |
const difference = nextMultiple - grade; | |
return [difference, nextMultiple] ; | |
} | |
let finalGrades = []; | |
for (let grade of grades) { | |
if (grade < 38 || findDiff(grade)[0] >= 3) finalGrades.push(grade); | |
else if (findDiff(grade)[0] < 3) { | |
finalGrades.push(findDiff(grade)[1]); | |
} | |
} | |
return finalGrades; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment