Merge pull request #46 from akshitgautam42/Ex-46

Exercise 46
This commit is contained in:
Akshit Gautam 2023-11-14 23:25:47 +05:30 committed by GitHub
commit ee3cf3cb60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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, u32>) {
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;
}
}