2020-12-27 17:34:42 +00:00
|
|
|
## bigger
|
|
|
|
|
|
|
|
### Instructions
|
|
|
|
|
2022-05-24 14:42:02 +00:00
|
|
|
Create a function named `bigger` that gets the biggest positive number in the `HashMap`.
|
2021-10-10 22:19:21 +00:00
|
|
|
|
2020-12-27 17:34:42 +00:00
|
|
|
### Expected Function
|
|
|
|
|
|
|
|
```rust
|
2020-12-29 12:53:44 +00:00
|
|
|
pub fn bigger(h: HashMap<&str, i32>) -> i32 {
|
2020-12-27 17:34:42 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
Here is a program to test your function.
|
|
|
|
|
|
|
|
```rust
|
2021-02-10 05:15:46 +00:00
|
|
|
use std::collections::HashMap;
|
2020-12-27 17:34:42 +00:00
|
|
|
use bigger::bigger;
|
2021-02-10 05:15:46 +00:00
|
|
|
|
2020-12-27 17:34:42 +00:00
|
|
|
fn main() {
|
2021-02-10 05:15:46 +00:00
|
|
|
|
2020-12-27 17:34:42 +00:00
|
|
|
let mut hash = HashMap::new();
|
|
|
|
hash.insert("Daniel", 122);
|
|
|
|
hash.insert("Ashley", 333);
|
|
|
|
hash.insert("Katie", 334);
|
|
|
|
hash.insert("Robert", 14);
|
|
|
|
|
|
|
|
println!("The biggest of the elements in the HashMap is {}", bigger(hash));
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
And its output
|
|
|
|
|
|
|
|
```console
|
2021-04-28 09:47:34 +00:00
|
|
|
$ cargo run
|
2020-12-29 12:53:44 +00:00
|
|
|
The biggest of the elements in the HashMap is 334
|
2021-04-28 09:47:34 +00:00
|
|
|
$
|
2020-12-27 17:34:42 +00:00
|
|
|
```
|
2022-05-24 14:42:02 +00:00
|
|
|
|
|
|
|
### Notions
|
|
|
|
|
|
|
|
- [hash maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html)
|