completed till 06/07
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// TODO: Flesh out the `WeekTemperatures` struct and its method implementations to pass the tests.
|
||||
|
||||
pub struct WeekTemperatures {
|
||||
// TODO
|
||||
temps: [Option<i32>; 7],
|
||||
}
|
||||
|
||||
pub enum Weekday {
|
||||
@@ -16,15 +16,15 @@ pub enum Weekday {
|
||||
|
||||
impl WeekTemperatures {
|
||||
pub fn new() -> Self {
|
||||
todo!()
|
||||
WeekTemperatures { temps: [None; 7] }
|
||||
}
|
||||
|
||||
pub fn get_temperature(&self, day: Weekday) -> Option<i32> {
|
||||
todo!()
|
||||
return self.temps[day as usize];
|
||||
}
|
||||
|
||||
pub fn set_temperature(&mut self, day: Weekday, temperature: i32) {
|
||||
todo!()
|
||||
self.temps[day as usize] = Some(temperature);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,11 @@ pub fn fibonacci(n: u32) -> u32 {
|
||||
//
|
||||
// Hint: use a `Vec` to memoize the results you have already calculated
|
||||
// so that you don't have to recalculate them several times.
|
||||
todo!()
|
||||
let mut fibNums = vec![0, 1];
|
||||
for i in 2..=n {
|
||||
fibNums.push(fibNums[(i - 1) as usize] + fibNums[(i - 2) as usize]);
|
||||
}
|
||||
fibNums[(n) as usize]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -12,6 +12,6 @@ mod tests {
|
||||
// Can you guess what the new capacity will be?
|
||||
// Beware that the standard library makes no guarantees about the
|
||||
// algorithm used to resize the vector, so this may change in the future.
|
||||
assert_eq!(v.capacity(), todo!());
|
||||
assert_eq!(v.capacity(), 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,14 @@ pub struct TicketStore {
|
||||
tickets: Vec<Ticket>,
|
||||
}
|
||||
|
||||
impl IntoIterator for TicketStore {
|
||||
type Item = Ticket;
|
||||
type IntoIter = std::vec::IntoIter<Self::Item>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
return self.tickets.into_iter();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Ticket {
|
||||
pub title: TicketTitle,
|
||||
|
||||
@@ -17,6 +17,20 @@ pub struct Ticket {
|
||||
status: Status,
|
||||
}
|
||||
|
||||
impl TicketStore {
|
||||
// type Itr=std::vec::I
|
||||
pub fn iter(&self) -> std::slice::Iter<Ticket> {
|
||||
self.tickets.iter()
|
||||
}
|
||||
}
|
||||
|
||||
// impl Iterator for TicketStore {
|
||||
// type Item = Ticket;
|
||||
// fn next(&mut self) -> Self::Item {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Clone, Debug, Copy, PartialEq)]
|
||||
pub enum Status {
|
||||
ToDo,
|
||||
|
||||
@@ -6,6 +6,14 @@ pub struct TicketStore {
|
||||
tickets: Vec<Ticket>,
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a TicketStore {
|
||||
type Item = &'a Ticket;
|
||||
type IntoIter = std::slice::Iter<'a, Ticket>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.tickets.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Ticket {
|
||||
pub title: TicketTitle,
|
||||
|
||||
@@ -7,6 +7,18 @@ pub struct TicketStore {
|
||||
tickets: Vec<Ticket>,
|
||||
}
|
||||
|
||||
impl TicketStore {
|
||||
fn to_dos(&self) -> Vec<&Ticket> {
|
||||
self.tickets
|
||||
.iter()
|
||||
.filter(|&a| match a.status {
|
||||
Status::ToDo => true,
|
||||
_ => false,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Ticket {
|
||||
pub title: TicketTitle,
|
||||
|
||||
Reference in New Issue
Block a user