Open
Description
https://github.com/rust-lang/rustlings/blob/main/exercises/12_options/options1.rs
options1.rs maybe_icecream
undefined for hour_of_day == 23
// This function returns how much icecream there is left in the fridge.
// If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00,
// someone eats it all, so no icecream is left (value 0). Return `None` if
// `hour_of_day` is higher than 23.
fn maybe_icecream(hour_of_day: u16) -> Option<u16> {
// TODO: Complete the function body.
if hour_of_day < 22 {
Some(5) // If it's before 22:00 (24-hour system), then 5 scoops are left.
} else if hour_of_day == 22 {
Some(0) // At 22:00, someone eats it all, so no icecream is left (value 0)
} else if hour_of_day > 23 {
None // Return `None` if `hour_of_day` is higher than 23.
} else {
Some(0) // this is only here to satisfy the contradicting test case
// assert_eq!(maybe_icecream(23), Some(0));
}
}
Metadata
Metadata
Assignees
Labels
No labels