Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Last active September 8, 2022 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nasah-Kuma/d3ee40523767514e0608cb97788daf53 to your computer and use it in GitHub Desktop.
Save Nasah-Kuma/d3ee40523767514e0608cb97788daf53 to your computer and use it in GitHub Desktop.
/*
* 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