complete: hashmap
This commit is contained in:
parent
6680e6d202
commit
26374eb122
exercises/collections
|
@ -11,17 +11,17 @@
|
|||
// Execute the command `rustlings hint hashmap1` if you need
|
||||
// hints.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn fruit_basket() -> HashMap<String, u32> {
|
||||
let mut basket = // TODO: declare your hash map here.
|
||||
let mut basket = HashMap::new();// TODO: declare your hash map here.
|
||||
|
||||
// Two bananas are already given for you :)
|
||||
basket.insert(String::from("banana"), 2);
|
||||
|
||||
// TODO: Put more fruits in your basket here.
|
||||
basket.insert(String::from("apple"), 2);
|
||||
basket.insert(String::from("orange"), 2);
|
||||
|
||||
basket
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
// Execute the command `rustlings hint hashmap2` if you need
|
||||
// hints.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
|
@ -38,6 +36,7 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
|
|||
// TODO: Put new fruits if not already present. Note that you
|
||||
// are not allowed to put any type of fruit that's already
|
||||
// present!
|
||||
basket.entry(fruit).or_insert(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue