-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
531 additions
and
545 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import gleam/map.{type Map} | ||
import gleam/dict.{type Dict} | ||
|
||
pub type ScoreBoard = | ||
Map(String, Int) | ||
Dict(String, Int) | ||
|
||
pub fn create_score_board() -> ScoreBoard { | ||
map.from_list([#("The Best Ever", 1_000_000)]) | ||
dict.from_list([#("The Best Ever", 1_000_000)]) | ||
} | ||
|
||
pub fn add_player( | ||
score_board: ScoreBoard, | ||
player: String, | ||
score: Int, | ||
) -> ScoreBoard { | ||
map.insert(score_board, player, score) | ||
dict.insert(score_board, player, score) | ||
} | ||
|
||
pub fn remove_player(score_board: ScoreBoard, player: String) -> ScoreBoard { | ||
map.delete(score_board, player) | ||
dict.delete(score_board, player) | ||
} | ||
|
||
pub fn update_score( | ||
score_board: ScoreBoard, | ||
player: String, | ||
points: Int, | ||
) -> ScoreBoard { | ||
case map.get(score_board, player) { | ||
Ok(score) -> map.insert(score_board, player, score + points) | ||
case dict.get(score_board, player) { | ||
Ok(score) -> dict.insert(score_board, player, score + points) | ||
Error(Nil) -> score_board | ||
} | ||
} | ||
|
||
pub fn apply_monday_bonus(score_board: ScoreBoard) -> ScoreBoard { | ||
map.map_values(score_board, fn(_, score) { score + 100 }) | ||
dict.map_values(score_board, fn(_, score) { score + 100 }) | ||
} |
4 changes: 2 additions & 2 deletions
4
exercises/concept/high-score-board/src/high_score_board.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.