Skip to content

Instantly share code, notes, and snippets.

@topeogunleye
Created June 16, 2022 07:40
Show Gist options
  • Save topeogunleye/4dc235aea4fd9681b27a2d88c1f0968f to your computer and use it in GitHub Desktop.
Save topeogunleye/4dc235aea4fd9681b27a2d88c1f0968f to your computer and use it in GitHub Desktop.
Grading Students
function gradingStudents(grades) {
// Write your code here
// if grades >= 40
// check if grade - next multiple of 5 is less than 3
// if less than 3 round
// else return grade unrounded
let results = []
function getNearestMultiple(number, multiple) {
return number + (multiple - (number % multiple));
}
for (let i = 0; i < grades; i++) {
if (grades[i] >= 40) {
let muliple = getNearestMultiple(grades[i], 5)
if (multiple - grades[i] < 3) {
results.push(multiple)
} else {
results.push(grades[i])
}
} else {
results.push(grades[i])
}
}
// console.log(results)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment