From 4e8d19a2c6a067b81153280282fdeb8f350c03a8 Mon Sep 17 00:00:00 2001 From: blacktoast Date: Wed, 13 Oct 2021 06:43:44 +0000 Subject: [PATCH] colection done --- exercises/collections/hashmap1.rs | 6 ++++-- exercises/collections/hashmap2.rs | 10 +++++++++- exercises/strings/strings1.rs | 3 +-- exercises/strings/strings2.rs | 7 ++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/exercises/collections/hashmap1.rs b/exercises/collections/hashmap1.rs index 64b5a7f3..6e0a32ff 100644 --- a/exercises/collections/hashmap1.rs +++ b/exercises/collections/hashmap1.rs @@ -11,15 +11,16 @@ // Execute the command `rustlings hint hashmap1` if you need // hints. -// I AM NOT DONE use std::collections::HashMap; fn fruit_basket() -> HashMap { - 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); + basket.insert(String::from("apple"), 2); + basket.insert(String::from("photo"), 1); // TODO: Put more fruits in your basket here. @@ -33,6 +34,7 @@ mod tests { #[test] fn at_least_three_types_of_fruits() { let basket = fruit_basket(); + println!("{}",basket.len()); assert!(basket.len() >= 3); } diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index 0abe19ab..17a61a7c 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -12,7 +12,6 @@ // Execute the command `rustlings hint hashmap2` if you need // hints. -// I AM NOT DONE use std::collections::HashMap; @@ -35,6 +34,15 @@ fn fruit_basket(basket: &mut HashMap) { ]; 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 // are not allowed to put any type of fruit that's already // present! diff --git a/exercises/strings/strings1.rs b/exercises/strings/strings1.rs index 80902444..aff1a4ac 100644 --- a/exercises/strings/strings1.rs +++ b/exercises/strings/strings1.rs @@ -2,7 +2,6 @@ // Make me compile without changing the function signature! // Execute `rustlings hint strings1` for hints ;) -// I AM NOT DONE fn main() { let answer = current_favorite_color(); @@ -10,5 +9,5 @@ fn main() { } fn current_favorite_color() -> String { - "blue" + "blue".to_string() } diff --git a/exercises/strings/strings2.rs b/exercises/strings/strings2.rs index 5a2ce74a..8a19ae9c 100644 --- a/exercises/strings/strings2.rs +++ b/exercises/strings/strings2.rs @@ -6,11 +6,16 @@ fn main() { 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!"); } else { 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 {