mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-13 21:03:31 +02:00
feat: progress iterators
This commit is contained in:
@@ -11,21 +11,31 @@ enum DivisionError {
|
||||
// TODO: Calculate `a` divided by `b` if `a` is evenly divisible by `b`.
|
||||
// Otherwise, return a suitable error.
|
||||
fn divide(a: i64, b: i64) -> Result<i64, DivisionError> {
|
||||
todo!();
|
||||
if b == 0 {
|
||||
Err(DivisionError::DivideByZero)
|
||||
} else if b == -1 && a == i64::MIN {
|
||||
Err(DivisionError::IntegerOverflow)
|
||||
} else if a % b == 0 {
|
||||
Ok(a / b)
|
||||
} else {
|
||||
Err(DivisionError::NotDivisible)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add the correct return type and complete the function body.
|
||||
// Desired output: `Ok([1, 11, 1426, 3])`
|
||||
fn result_with_list() {
|
||||
fn result_with_list() -> Result<Vec<i64>, DivisionError> {
|
||||
let numbers = [27, 297, 38502, 81];
|
||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
||||
division_results.collect()
|
||||
}
|
||||
|
||||
// TODO: Add the correct return type and complete the function body.
|
||||
// Desired output: `[Ok(1), Ok(11), Ok(1426), Ok(3)]`
|
||||
fn list_of_results() {
|
||||
fn list_of_results() -> Vec<Result<i64, DivisionError>> {
|
||||
let numbers = [27, 297, 38502, 81];
|
||||
let division_results = numbers.into_iter().map(|n| divide(n, 27));
|
||||
division_results.collect()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user