From cfd12734d330398e9ae5a1173320ad7335a0fb8f Mon Sep 17 00:00:00 2001 From: MSilva95 Date: Tue, 29 Dec 2020 12:53:44 +0000 Subject: [PATCH] fixing errors from augusto pr --- subjects/bigger/README.md | 4 ++-- subjects/division_and_remainder/README.md | 6 +++-- subjects/simple_hash/README.md | 29 ++++++++++++++--------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/subjects/bigger/README.md b/subjects/bigger/README.md index ae1e9ee19..fbd38a809 100644 --- a/subjects/bigger/README.md +++ b/subjects/bigger/README.md @@ -7,7 +7,7 @@ Create the function `bigger` that gets the biggest positive number in the `HashM ### Expected Function ```rust -fn bigger(h: HashMap<&str, i32>) -> i32 { +pub fn bigger(h: HashMap<&str, i32>) -> i32 { } ``` @@ -33,6 +33,6 @@ And its output ```console student@ubuntu:~/[[ROOT]]/test$ cargo run -Is `thought` a permutation of `thougth`? = true +The biggest of the elements in the HashMap is 334 student@ubuntu:~/[[ROOT]]/test$ ``` diff --git a/subjects/division_and_remainder/README.md b/subjects/division_and_remainder/README.md index 6d345e6ad..f6a758da8 100644 --- a/subjects/division_and_remainder/README.md +++ b/subjects/division_and_remainder/README.md @@ -7,7 +7,7 @@ Create a function divide that receives two i32 and returns a tuple in which the ### Expected Function ```rust -fn divide(x: i32, y: i32) -> (i32, i32) { +pub fn divide(x: i32, y: i32) -> (i32, i32) { } ``` @@ -17,12 +17,14 @@ fn divide(x: i32, y: i32) -> (i32, i32) { Here is a program to test you're function ```rust +use division_and_remainder::division_and_remainder; + fn main() { let x = 9; let y = 4; let (division, remainder) = divide(x, y); println!( - "\t{}/{}: division = {}, remainder = {}", + "{}/{}: division = {}, remainder = {}", x, y, division, remainder ); } diff --git a/subjects/simple_hash/README.md b/subjects/simple_hash/README.md index f671b5c67..15de390b4 100644 --- a/subjects/simple_hash/README.md +++ b/subjects/simple_hash/README.md @@ -2,18 +2,20 @@ ### Instructions -- Create the function `contain` that checks a `HashMap` to see if it contains the given key. +Create the function `contain` that checks a `HashMap` to see if it contains the given key. -- Create the function `remove` that removes a given key from the `HashMap`. +Create the function `remove` that removes a given key from the `HashMap`. -### Expected Functions +### Notions + +- https://doc.rust-lang.org/rust-by-example/std/hash.html + +### Expected functions ```rust -fn contain(h: HashMap<&str, i32>, s: &str) -> bool { -} +pub fn contain(h: &HashMap<&str, i32>, s: &str) -> bool {} -fn remove(mut h: HashMap<&str, i32>, s: &str) { -} +pub fn remove(h: &mut HashMap<&str, i32>, s: &str) {} ``` ### Usage @@ -32,13 +34,17 @@ fn main() { println!( "Does the HashMap contains the name Roman? => {}", - contain(hash.clone(), "Roman") + contain(&hash, "Roman") ); println!( "Does the HashMap contains the name Katie? => {}", - contain(hash.clone(), "Katie") + contain(&hash, "Katie") + ); + println!("Removing Robert {:?}", remove(&mut hash, "Robert")); + println!( + "Does the HashMap contains the name Robert? => {}", + contain(&hash, "Robert") ); - println!("Removing Robert {:?}", remove(hash.clone(), "Robert")); println!("Hash {:?}", hash); } ``` @@ -50,6 +56,7 @@ student@ubuntu:~/[[ROOT]]/test$ cargo run Does the HashMap contains the name Roman? => false Does the HashMap contains the name Katie? => true Removing Robert () -Hash {"Daniel": 122, "Ashley": 333, "Robert": 14, "Katie": 334} +Does the HashMap contains the name Robert? => false +Hash {"Katie": 334, "Daniel": 122, "Ashley": 333} student@ubuntu:~/[[ROOT]]/test$ ```