mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
Highest
Instructions
In this exercise a Numbers
struct will be given.
These methods have to be written:
new
create a new instance of Number.List
that returns anarray
with every number in the struct.Latest
that returns anOption<u32>
with the last added number.Highest
that return anOption<u32>
with the highest number from the list.Highest_Three
that returns aVec<u32>
with the three highest numbers.
Notions
Expected functions
pub fn new(&[u32]) -> Self {}
pub fn List(&self) -> &[u32] {}
pub fn Latest(&self) -> Option<u32> {}
pub fn Highest(&self) -> Option<u32> {}
pub fn Highest_Three(&self) -> Vec<u32> {}
Usage
Here is a program to test your function.
use highest::*;
#[derive(Debug)]
struct Numbers<'a> {
numbers: &'a [u32],
}
fn main() {
let expected = [30, 500, 20, 70];
let n = Numbers::new(&expected);
println!("{:?}", n.List());
println!("{:?}", n.Highest());
println!("{:?}", n.Latest());
println!("{:?}", n.Highest_Three());
}
And its output:
$ cargo run
[30, 500, 20, 70]
Some(500)
Some(70)
[500, 70, 30]
$