diff --git a/exercises/11_hashmaps/hashmaps2.rs b/exercises/11_hashmaps/hashmaps2.rs index a5925690..8a44b1eb 100644 --- a/exercises/11_hashmaps/hashmaps2.rs +++ b/exercises/11_hashmaps/hashmaps2.rs @@ -14,7 +14,7 @@ // Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE + use std::collections::HashMap; @@ -36,10 +36,20 @@ fn fruit_basket(basket: &mut HashMap) { Fruit::Pineapple, ]; + + for fruit in fruit_kinds { // 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! + if !basket.contains_key(&fruit){ + basket.insert(fruit,1); + } + } + + let total_count:u32 = basket.values().sum(); + if total_count <=11{ + *basket.entry(Fruit::Pineapple).or_insert(0)+=12-total_count; } }