Ad
Mathematics
Algorithms
Logic
Numbers
Data Types

Code a function that will return the exact average grade of an array of grades.

Code
Diff
  • function average(grades) {
      if (grades && grades.length) {
        return grades.reduce((total, grade) => total + grade, 0) / grades.length
      }
    }
    • def average(grades)
    • grades.sum.to_f / grades.size unless grades.empty?
    • end
    • function average(grades) {
    • if (grades && grades.length) {
    • return grades.reduce((total, grade) => total + grade, 0) / grades.length
    • }
    • }