From b42cfb167d911ca8fb55b4edc99739ef8b12483b Mon Sep 17 00:00:00 2001 From: Rock070 Date: Sat, 30 Dec 2023 17:15:50 +0800 Subject: [PATCH] Add new fruits to the basket if not already present --- exercises/11_hashmaps/hashmaps2.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exercises/11_hashmaps/hashmaps2.rs b/exercises/11_hashmaps/hashmaps2.rs index a5925690..80115b1e 100644 --- a/exercises/11_hashmaps/hashmaps2.rs +++ b/exercises/11_hashmaps/hashmaps2.rs @@ -14,8 +14,6 @@ // Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE - use std::collections::HashMap; #[derive(Hash, PartialEq, Eq)] @@ -37,6 +35,7 @@ fn fruit_basket(basket: &mut HashMap) { ]; for fruit in fruit_kinds { + basket.entry(fruit).or_insert(1); // TODO: Insert new fruits if they are not already present in the // basket. Note that you are not allowed to put any type of fruit that's // already present!