Pattern matching for the win!
I didn't know what to do with the base_power thing, so I left it as one.
base_power
Elixir
defmodule Pokemon do def calculate(effectiveness, attack, defence) do 1 * (attack / defence) * effectiveness end def total_damage(a, a, att, def), do: calculate(0.5, att, def) def total_damage("electric", "water", att, def), do: calculate(2, att, def) def total_damage("fire", "grass", att, def), do: calculate(2, att, def) def total_damage("fire", "water", att, def), do: calculate(0.5, att, def) def total_damage("grass", "fire", att, def), do: calculate(0.5, att, def) def total_damage("grass", "water", att, def), do: calculate(2, att, def) def total_damage("water", "electric", att, def), do: calculate(0.5, att, def) def total_damage("water", "fire", att, def), do: calculate(2, att, def) def total_damage("water", "grass", att, def), do: calculate(0.5, att, def) def total_damage(_, _, att, def), do: calculate(1, att, def) end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Pattern matching for the win!
I didn't know what to do with the
base_power
thing, so I left it as one.Elixir