Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1x 1x 7x 7x 2x 5x 2x 7x | // https://www.codewars.com/kata/536e9a7973130a06eb000e9f interface TypeMatchups { supereffective: string[]; neutral: string[]; noteffective: string[]; } interface BattleTypes { [key: string]: TypeMatchups; } const battleMatchups: BattleTypes = { fire: { supereffective: ['grass'], neutral: ['electric', 'fire'], noteffective: ['water'] }, water: { supereffective: ['fire'], neutral: ['electric', 'water'], noteffective: ['grass'] }, grass: { supereffective: ['water'], neutral: ['grass', 'electric'], noteffective: ['fire'] }, electric: { supereffective: ['water'], neutral: ['electric', 'fire'], noteffective: [] } }; export function calculateDamage(yourType: string, opponentType: string, attack: number, defence: number): number { let multiplier: number = 1; if (battleMatchups[yourType].supereffective.includes(opponentType)) { multiplier = 2; } else if (battleMatchups[yourType].noteffective.includes(opponentType)) { multiplier = 0.5; } return 50 * (attack / defence) * multiplier; } |