DEV Community

Discussion on: Daily Challenge #68 - Grade Book

Collapse
 
kvharish profile image
K.V.Harish • Edited

My solution in js

const grade = (...values) => {
  const grades = {9: 'A', 8: 'B', 7: 'C', 6: 'D'},
    mean = values.reduce((acc, value) => acc += value, 0) / values.length;
  return grades[Math.floor(mean / 10)] ? `${grades[Math.floor(mean / 10)]}${mean >= (Math.floor(mean / 10) * 10 + 5) ? '+' : '-'}` : Math.floor(mean / 10) > 9 ? 'A+' : 'F'
}