Compare commits

...

4 Commits

Author SHA1 Message Date
f32a3c31fe it works consistently 2024-08-26 16:28:26 +05:30
3127d21afa compact code for unreadability 2024-08-26 12:41:15 +05:30
6f7fc02d24 return 'Ab' for non numeric inputs 2024-08-26 12:32:14 +05:30
300265bc3f add jsdoc 2024-08-26 12:23:11 +05:30

View File

@@ -30,32 +30,32 @@ const grades = [
} }
] ]
/**
* 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){ 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 if (isNaN(Number(mark))) return 'Ab'
if (mark > 100 || mark < 0) return 'OUT OF MARK RANGE'
for (let j=i;j>0;j--) { main: for (let i=0;i<grades.length;i++){
const {min,grade} = grades[j] printdebug({i})
printdebug({j,min}) if (mark > grades[i].max) continue
if (mark < min) continue while (grades[i].min > mark){
return grade if (++i === grades.length) break main
printdebug({i})
} }
return grades[i].grade
} }
return 'Ab'
//const [{grade}] = grades.filter(({max,min}) => mark <= max && mark >= min)
//return grade
} }
const grade = getGrade(argv[2]) const grade = getGrade(argv[2])
console.log(grade) console.log(grade)
function printdebug(text) { function printdebug(text){ if (DEBUG)console.error('DEBUG:',text) }
if (DEBUG) {
console.error('DEBUG:',text)
}
}