mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-04 01:39:18 +00:00
Fix maybe_icecream function to handle time_of_day correctly
This commit is contained in:
parent
b4cf7e4ef8
commit
439778465d
@ -13,7 +13,13 @@ fn maybe_icecream(time_of_day: u16) -> Option<u16> {
|
||||
// value of 0 The Option output should gracefully handle cases where
|
||||
// time_of_day > 23.
|
||||
// TODO: Complete the function body - remember to return an Option!
|
||||
???
|
||||
if time_of_day >= 22 && time_of_day <= 24 {
|
||||
return Some(0);
|
||||
} else if time_of_day >= 24 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Option::Some(5)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -34,6 +40,6 @@ mod tests {
|
||||
// TODO: Fix this test. How do you get at the value contained in the
|
||||
// Option?
|
||||
let icecreams = maybe_icecream(12);
|
||||
assert_eq!(icecreams, 5);
|
||||
assert_eq!(icecreams, Some(5));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user