completed till 06/07

This commit is contained in:
2025-04-01 07:15:32 +05:30
parent 2fa61e7715
commit f980a3b381
7 changed files with 52 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
// TODO: Flesh out the `WeekTemperatures` struct and its method implementations to pass the tests. // TODO: Flesh out the `WeekTemperatures` struct and its method implementations to pass the tests.
pub struct WeekTemperatures { pub struct WeekTemperatures {
// TODO temps: [Option<i32>; 7],
} }
pub enum Weekday { pub enum Weekday {
@@ -16,15 +16,15 @@ pub enum Weekday {
impl WeekTemperatures { impl WeekTemperatures {
pub fn new() -> Self { pub fn new() -> Self {
todo!() WeekTemperatures { temps: [None; 7] }
} }
pub fn get_temperature(&self, day: Weekday) -> Option<i32> { 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) { pub fn set_temperature(&mut self, day: Weekday, temperature: i32) {
todo!() self.temps[day as usize] = Some(temperature);
} }
} }

View File

@@ -15,7 +15,11 @@ pub fn fibonacci(n: u32) -> u32 {
// //
// Hint: use a `Vec` to memoize the results you have already calculated // Hint: use a `Vec` to memoize the results you have already calculated
// so that you don't have to recalculate them several times. // 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)] #[cfg(test)]

View File

@@ -12,6 +12,6 @@ mod tests {
// Can you guess what the new capacity will be? // Can you guess what the new capacity will be?
// Beware that the standard library makes no guarantees about the // Beware that the standard library makes no guarantees about the
// algorithm used to resize the vector, so this may change in the future. // algorithm used to resize the vector, so this may change in the future.
assert_eq!(v.capacity(), todo!()); assert_eq!(v.capacity(), 4);
} }
} }

View File

@@ -13,6 +13,14 @@ pub struct TicketStore {
tickets: Vec<Ticket>, 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)] #[derive(Clone, Debug, PartialEq)]
pub struct Ticket { pub struct Ticket {
pub title: TicketTitle, pub title: TicketTitle,

View File

@@ -17,6 +17,20 @@ pub struct Ticket {
status: Status, 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)] #[derive(Clone, Debug, Copy, PartialEq)]
pub enum Status { pub enum Status {
ToDo, ToDo,

View File

@@ -6,6 +6,14 @@ pub struct TicketStore {
tickets: Vec<Ticket>, 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)] #[derive(Clone, Debug, PartialEq)]
pub struct Ticket { pub struct Ticket {
pub title: TicketTitle, pub title: TicketTitle,

View File

@@ -7,6 +7,18 @@ pub struct TicketStore {
tickets: Vec<Ticket>, 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)] #[derive(Clone, Debug, PartialEq)]
pub struct Ticket { pub struct Ticket {
pub title: TicketTitle, pub title: TicketTitle,