Today's challenge is to write a function that accepts three integer values, calculates the mean, then returns the letter value associated with that grade. If the mean of those three integers ends in a number greater than five, append a plus sign to the letter grade. If it is less than five, append a minus sign.
Numerical Score Letter Grade 90 <= score <= 100 'A' 80 <= score < 90 'B' 70 <= score < 80 'C' 60 <= score < 70 'D' 0 <= score < 60 'F'
Examples:
grade(64, 55, 92) => C- (70.3)
grade(99, 89, 93) => A- (93.6)
grade(33, 99, 95) => C+ (75.6)
Happy coding!
This challenge was inspired by CodeWars user danleavitt0. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (19)
My solution in js
Solved Using Purescript inspired from Amin Nairi
Scala
APL (I'm using Dyalog APL):
{md←10|m←(+⌿÷⍴)⍵ ⋄ ((1+60 70 80 90 101⍸m)⊃'FDCBA'),' -+'[1+(md≠5)×1+(,5)⍸md]}If you think that's too short to work - here's the proof:
First, let's define that as a function:
getMark←{md←10|m←(+⌿÷⍴)⍵ ⋄ ((1+60 70 80 90 101⍸m)⊃'FDCBA'),' -+'[1+(md≠5)×1+(,5)⍸md]}And now you can simply do
getMark 64 55 92C-
getMark 99 89 93A-
getMark 33 99 95C+
And if you still don't believe me, try it here or there! ;-)
(These online solutions use the symbol ≢ instead of ⍴ - they are equivalent in this case, but ≢ renders incorrectly on dev.to. There's also an issue with another APL-Character: ⍸ - if someone from the dev-team would contact me, I'd love to help sorting that out...)
This is my quick python solution
My first stab at writing something other than "Hello World!" in golang:
I wrote this in Python with the assumption that the input of the function will all be integers between 0 and 100.
Perl solution, using a regex to extract the last digit (but we need to replace 100 by 99 for it to work).
Here's my type-level implementation in haskell:
Clojure (my new adventure):