Skip to content

Instantly share code, notes, and snippets.

@nicohvi

nicohvi/pokemon.ts

Last active Aug 5, 2018
Embed
What would you like to do?
function getAttackPower(pokemon: Pokemon) {
return pokemon.level * pokemon.attackPower;
}
function defend(pokemon: Pokemon, damage: number) {
const hp = pokemon.hp - damage;
return Object.assign({}, pokemon, { hp });
}
function performAttack(attacker: Pokemon, defender: Pokemon) {
const dmg = getAttackPower(attacker);
return {
attacker,
defender: defend(defender, dmg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment