loading...

re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

Scala

def grade (a: Int, b: Int, c: Int): String = {
  val average = (a + b + c) / 3f
  letter(average) ++ sign(average)
}

def letter (grade: Float): String =
  grade match {
    case x if x >= 90 => "A"
    case x if x >= 80 => "B"
    case x if x >= 70 => "C"
    case x if x >= 60 => "D"
    case _            => "F"
  }

def sign (grade: Float): String =
  (grade % 10) match {
    case x if x < 5 => "-"
    case x if x > 5 => "+"
    case _          => ""
  }
code of conduct - report abuse