Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
hampuskraft committed Aug 26, 2022
1 parent 7c50382 commit baf635f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ bracketSpacing: false
printWidth: 120
proseWrap: always
quoteProps: consistent
semi: false
singleQuote: true
trailingComma: all
28 changes: 12 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
function solveQuadratic(a: number, b: number, c: number): number[] {
const discrim = b ** 2 - 4 * a * c;
const discrim = b ** 2 - 4 * a * c
if (discrim > 0) {
const sqrtDiscrim = Math.sqrt(discrim);
return [(-b + sqrtDiscrim) / (2 * a), (-b - sqrtDiscrim) / (2 * a)];
const sqrtDiscrim = Math.sqrt(discrim)
return [(-b + sqrtDiscrim) / (2 * a), (-b - sqrtDiscrim) / (2 * a)]
}
return discrim === 0 ? [-b / (2 * a)] : [];
return discrim === 0 ? [-b / (2 * a)] : []
}

export function getXpToReachLevel(level: number): number {
if (level <= 16) {
return level ** 2 + level * 6;
}
if (level <= 31) {
return level ** 2 * 2.5 - 40.5 * level + 360;
}
return level ** 2 * 4.5 - 162.5 * level + 2220;
if (level <= 16) return level ** 2 + level * 6
if (level <= 31) return level ** 2 * 2.5 - 40.5 * level + 360
return level ** 2 * 4.5 - 162.5 * level + 2220
}

export function getLevelFromXp(xp: number): number {
const a = xp <= getXpToReachLevel(16) ? 1 : xp <= getXpToReachLevel(31) ? 2.5 : 4.5;
const b = xp <= getXpToReachLevel(16) ? 6 : xp <= getXpToReachLevel(31) ? -40.5 : -162.5;
const c = xp <= getXpToReachLevel(16) ? 0 : xp <= getXpToReachLevel(31) ? 360 : 2220;
const x = solveQuadratic(a, b, c - xp);
return ~~Math.max(...x);
const a = xp <= getXpToReachLevel(16) ? 1 : xp <= getXpToReachLevel(31) ? 2.5 : 4.5
const b = xp <= getXpToReachLevel(16) ? 6 : xp <= getXpToReachLevel(31) ? -40.5 : -162.5
const c = xp <= getXpToReachLevel(16) ? 0 : xp <= getXpToReachLevel(31) ? 360 : 2220
const x = solveQuadratic(a, b, c - xp)
return ~~Math.max(...x)
}

0 comments on commit baf635f

Please sign in to comment.