70 lines
1.1 KiB
JavaScript
70 lines
1.1 KiB
JavaScript
import { argv } from 'node:process';
|
|
import { env } from 'node:process';
|
|
|
|
const DEBUG = Boolean(env.DEBUG);
|
|
|
|
const grades = [
|
|
{
|
|
grade: 'A1', min: 91, max: 100
|
|
},
|
|
{
|
|
grade: 'A2', min: 81, max: 90
|
|
},
|
|
{
|
|
grade: 'B1', min: 71, max: 80
|
|
},
|
|
{
|
|
grade: 'B2', min: 61, max: 70
|
|
},
|
|
{
|
|
grade: 'C1', min: 51, max: 60
|
|
},
|
|
{
|
|
grade: 'C2', min: 41, max: 50
|
|
},
|
|
{
|
|
grade: 'D', min: 33, max: 40
|
|
},
|
|
{
|
|
grade: 'E', min: 0, max: 32
|
|
}
|
|
]
|
|
|
|
/**
|
|
* Returns the grade corresponding to mark.
|
|
*
|
|
* @param {number} input The marks out of 100.
|
|
* @return The corresponding grade of the marks.
|
|
* @customfunction
|
|
*/
|
|
|
|
function getGrade(mark){
|
|
if (typeof(mark) != 'number')
|
|
for (let i=0;i<=grades.length-1;i++){
|
|
const {max} = grades[i]
|
|
printdebug({i,max})
|
|
|
|
if (max > mark) continue
|
|
|
|
for (let j=i;j>0;j--) {
|
|
const {min,grade} = grades[j]
|
|
printdebug({j,min})
|
|
if (mark < min) continue
|
|
return grade
|
|
}
|
|
}
|
|
return 'Ab'
|
|
//const [{grade}] = grades.filter(({max,min}) => mark <= max && mark >= min)
|
|
//return grade
|
|
}
|
|
|
|
|
|
const grade = getGrade(argv[2])
|
|
console.log(grade)
|
|
|
|
function printdebug(text) {
|
|
if (DEBUG) {
|
|
console.error('DEBUG:',text)
|
|
}
|
|
}
|