-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create endpoint for course summary (#75)
* Create summary endpoint * Improve tests
- Loading branch information
1 parent
991941f
commit 8b05e69
Showing
4 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const EXP_POINTS = { | ||
hard: { perfect: 200, withMistakes: 100 }, | ||
medium: { perfect: 100, withMistakes: 50 }, | ||
easy: { perfect: 50, withMistakes: 25 }, | ||
}; | ||
|
||
export type Difficulty = keyof typeof EXP_POINTS; | ||
|
||
export const calculateExperience = (difficulty: Difficulty, correctAtFirstTry: boolean) => { | ||
return correctAtFirstTry ? EXP_POINTS[difficulty].perfect : EXP_POINTS[difficulty].withMistakes; | ||
}; | ||
|
||
export const calculateLevel = (exp: number): number => { | ||
let level = 0; | ||
while (10 * Math.pow(level, 2) + 100 * level + 150 < exp) { | ||
level++; | ||
} | ||
return level; | ||
}; | ||
|
||
export const calculateXpToNextLevel = (exp: number, currentLevel: number): number => { | ||
const nextLevelExp = 10 * Math.pow(currentLevel, 2) + 100 * currentLevel + 150; | ||
return nextLevelExp - exp; | ||
}; |
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
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