re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

Clojure (my new adventure):

(def grades {"A" [90 101]
             "B" [80 90]
             "C" [70 80]
             "D" [60 70]
             "F" [0 60]})

(defn grade
  "Calculates a letter for the mean of given grades."
  [a b c]
  (let [mean (quot (+ a b c) 3)
        sign (if (< (rem mean 10) 5) "-" "+")
        letter (->> grades
                   (filter (fn [[_ [low high]]]
                             (and (>= mean low) (< mean high))))
                   (map key)
                   first)]
    (str letter sign)))
code of conduct - report abuse