colection done

This commit is contained in:
blacktoast 2021-10-13 06:43:44 +00:00
parent 14d63e2b8e
commit 4e8d19a2c6
4 changed files with 20 additions and 6 deletions

View File

@ -11,15 +11,16 @@
// Execute the command `rustlings hint hashmap1` if you need // Execute the command `rustlings hint hashmap1` if you need
// hints. // hints.
// I AM NOT DONE
use std::collections::HashMap; use std::collections::HashMap;
fn fruit_basket() -> HashMap<String, u32> { 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 :) // Two bananas are already given for you :)
basket.insert(String::from("banana"), 2); basket.insert(String::from("banana"), 2);
basket.insert(String::from("apple"), 2);
basket.insert(String::from("photo"), 1);
// TODO: Put more fruits in your basket here. // TODO: Put more fruits in your basket here.
@ -33,6 +34,7 @@ mod tests {
#[test] #[test]
fn at_least_three_types_of_fruits() { fn at_least_three_types_of_fruits() {
let basket = fruit_basket(); let basket = fruit_basket();
println!("{}",basket.len());
assert!(basket.len() >= 3); assert!(basket.len() >= 3);
} }

View File

@ -12,7 +12,6 @@
// Execute the command `rustlings hint hashmap2` if you need // Execute the command `rustlings hint hashmap2` if you need
// hints. // hints.
// I AM NOT DONE
use std::collections::HashMap; use std::collections::HashMap;
@ -35,6 +34,15 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
]; ];
for fruit in fruit_kinds { for fruit in fruit_kinds {
match fruit {
Fruit::Apple=>{basket.insert(fruit,4);}
Fruit::Banana=>{basket.insert(fruit,2);}
Fruit::Mango=>{basket.insert(fruit,2);}
Fruit::Lychee=>{basket.insert(fruit,5);}
Fruit::Pineapple=>{basket.insert(fruit,2);}
_=>()
}
// TODO: Put new fruits if not already present. Note that you // TODO: Put new fruits if not already present. Note that you
// are not allowed to put any type of fruit that's already // are not allowed to put any type of fruit that's already
// present! // present!

View File

@ -2,7 +2,6 @@
// Make me compile without changing the function signature! // Make me compile without changing the function signature!
// Execute `rustlings hint strings1` for hints ;) // Execute `rustlings hint strings1` for hints ;)
// I AM NOT DONE
fn main() { fn main() {
let answer = current_favorite_color(); let answer = current_favorite_color();
@ -10,5 +9,5 @@ fn main() {
} }
fn current_favorite_color() -> String { fn current_favorite_color() -> String {
"blue" "blue".to_string()
} }

View File

@ -6,11 +6,16 @@
fn main() { fn main() {
let word = String::from("green"); // Try not changing this line :) let word = String::from("green"); // Try not changing this line :)
if is_a_color_word(word) { if is_a_color_word(&word) {
println!("That is a color word I know!"); println!("That is a color word I know!");
} else { } else {
println!("That is not a color word I know."); println!("That is not a color word I know.");
} }
let t="tic";
let to="tac";
let too="too";
let sum=format!("{}-{}-hi {}",t,to,too);
println!("{}",sum);
} }
fn is_a_color_word(attempt: &str) -> bool { fn is_a_color_word(attempt: &str) -> bool {