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
// 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);
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);
}

View File

@ -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<Fruit, u32>) {
];
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!

View File

@ -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()
}

View File

@ -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 {