Skip to content

Commit

Permalink
fix(grades): format null grades to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
SeGonzalezR committed Aug 19, 2024
1 parent e1c6bac commit f05ca0e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"javascript.implicitProjectConfig.checkJs": true,
"javascript.validate.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
3 changes: 3 additions & 0 deletions lib/grades/gradeFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Agrega puntos, comas, caracteres antes o despues de la nota.
* @example const formated = gradeFormat(scale, grade)
*/
export const gradeFormat = (scale: ScaleAttributes, grade: number): string => {
if (grade === null) {
grade = 0
}
let round = `${gradeRound(scale, grade)}`

if (round.length === 1 && scale.append === '' && scale.base !== 'Peru') {
Expand Down
3 changes: 3 additions & 0 deletions lib/grades/gradeRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { ScaleAttributes } from '../types'
export const gradeRound = (scale: ScaleAttributes, grade: number): number => {
try {
let rounded: number | string
if (grade === null) {
return Number(0)
}
if (scale.decimals > 0) {
if (scale.decimals === 1) {
rounded = Number(
Expand Down

0 comments on commit f05ca0e

Please sign in to comment.