exercism/elixir/high-score/lib/high_score.ex

22 lines
466 B
Elixir
Raw Permalink Normal View History

2023-12-18 09:03:01 +00:00
defmodule HighScore do
@default_score 0
def new(),
do: %{}
def add_player(scores, name, score \\ @default_score),
do: Map.put(scores, name, score)
def remove_player(scores, name),
do: Map.delete(scores, name)
def reset_score(scores, name),
do: Map.put(scores, name, @default_score)
def update_score(scores, name, score),
do: Map.update(scores, name, score, &(&1 + score))
def get_players(scores),
do: Map.keys(scores)
end