Last active
July 4, 2022 07:53
-
-
Save prmichaelsen/6a14b0de25010357207cc2a72ee81a0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ts-node | |
const grades: [number, string][] = [ | |
[96, 'A+'], | |
[93, 'A' ], | |
[90, 'A-'], | |
[86, 'B+'], | |
[83, 'B '], | |
[80, 'B-'], | |
[76, 'C+'], | |
[73, 'C '], | |
[70, 'C-'], | |
[66, 'D+'], | |
[63, 'D '], | |
[60, 'D-'], | |
[56, 'F+'], | |
[53, 'F '], | |
[ 0, 'F-'], | |
]; | |
const easyFormat = (val: number) => { | |
const [_, grade] = | |
grades.find(([threshold]) => val >= threshold)!; | |
return grade; | |
} | |
console.log('A+', easyFormat(100)); | |
console.log('A+', easyFormat(96)); | |
console.log( 'B+', easyFormat(89)); | |
console.log( 'C-', easyFormat(70)); | |
console.log( 'C ', easyFormat(73)); | |
console.log( 'C ', easyFormat(75)); | |
console.log( 'D+', easyFormat(69)); | |
console.log( 'F-', easyFormat(50)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment