You are viewing a single comment's thread. Return to all comments →
Wow that's short!
I think you can make it even shorter without hurting readability too badly.
return grades.map(g => (g < 38 || g%5 < 3) ? g : Math.ceil(g/5)*5)
This would work too and is probably a little clearer.
return grades.map(g => (g < 38 || g%5 < 3) ? g : g+(5-(g%5)))
I did the same, and was making the same decision between Math.ceil(g/5)5 and g+(5-(g%5)) I ended up with the following:
const gradingStudents = grades => grades.map(grade=> grade <= 37 || grade % 5 < 3 ? grade : grade + (5 - grade % 5));