Skip to content

Instantly share code, notes, and snippets.

@prmichaelsen
Last active July 4, 2022 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prmichaelsen/6a14b0de25010357207cc2a72ee81a0f to your computer and use it in GitHub Desktop.
Save prmichaelsen/6a14b0de25010357207cc2a72ee81a0f to your computer and use it in GitHub Desktop.
#!/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