Too much ternary operators...
const grade = (a,b,c) =>{ const mean = (a + b + c) / 3; const prefix = mean % 10 < 5 ? '-': mean % 10 > 5 ? '+': ''; return mean < 59 ? `F (${mean})`: mean < 70 ? `D${prefix} (${mean})` : mean < 80 ? `C${prefix} (${mean})`: mean < 90 ? `B${prefix} (${mean})` : `A${prefix} (${mean})`; }
I've Started to write a c# answer only to find out I'm going the exact same route as your answer...
You could use something like that:
({"-1": "-", "1": "+", "0": ""})[mean.toString().localeCompare("5")]
Not tested but I believe it would work in JavaScript.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Too much ternary operators...
I've Started to write a c# answer only to find out I'm going the exact same route as your answer...
You could use something like that:
Not tested but I believe it would work in JavaScript.