mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-01-30 00:00:03 +03:00
Compare commits
No commits in common. "4d9c346a173bb722b929f3ea3c00f84954483e24" and "47f8199a996c098cfd64f5afa08284a588d2b874" have entirely different histories.
4d9c346a17
...
47f8199a99
|
@ -1,4 +1,4 @@
|
||||||
fn factorial(num: u64) -> u64 {
|
fn factorial(num: u8) -> u64 {
|
||||||
// TODO: Complete this function to return the factorial of `num`.
|
// TODO: Complete this function to return the factorial of `num`.
|
||||||
// Do not use:
|
// Do not use:
|
||||||
// - early returns (using the `return` keyword explicitly)
|
// - early returns (using the `return` keyword explicitly)
|
||||||
|
|
|
@ -47,23 +47,6 @@ fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Pr
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equivalent to `count_collection_iterator`+`count_iterator`, iterating as if
|
|
||||||
// the collection was a single container instead of a container of containers
|
|
||||||
// (and more accurately, a single iterator instead of an iterator of iterators).
|
|
||||||
fn count_collection_iterator_flat(
|
|
||||||
collection: &[HashMap<String, Progress>],
|
|
||||||
value: Progress,
|
|
||||||
) -> usize {
|
|
||||||
// `collection` is a slice of hash maps.
|
|
||||||
// collection = [{ "variables1": Complete, "from_str": None, … },
|
|
||||||
// { "variables2": Complete, … }, … ]
|
|
||||||
collection
|
|
||||||
.iter()
|
|
||||||
.flat_map(HashMap::values) // or just `.flatten()` when wanting the default iterator (`HashMap::iter`)
|
|
||||||
.filter(|val| **val == value)
|
|
||||||
.count()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// You can optionally experiment here.
|
// You can optionally experiment here.
|
||||||
}
|
}
|
||||||
|
@ -138,30 +121,18 @@ mod tests {
|
||||||
count_collection_iterator(&collection, Progress::Complete),
|
count_collection_iterator(&collection, Progress::Complete),
|
||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
assert_eq!(
|
|
||||||
count_collection_iterator_flat(&collection, Progress::Complete),
|
|
||||||
6,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn count_collection_some() {
|
fn count_collection_some() {
|
||||||
let collection = get_vec_map();
|
let collection = get_vec_map();
|
||||||
assert_eq!(count_collection_iterator(&collection, Progress::Some), 1);
|
assert_eq!(count_collection_iterator(&collection, Progress::Some), 1);
|
||||||
assert_eq!(
|
|
||||||
count_collection_iterator_flat(&collection, Progress::Some),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn count_collection_none() {
|
fn count_collection_none() {
|
||||||
let collection = get_vec_map();
|
let collection = get_vec_map();
|
||||||
assert_eq!(count_collection_iterator(&collection, Progress::None), 4);
|
assert_eq!(count_collection_iterator(&collection, Progress::None), 4);
|
||||||
assert_eq!(
|
|
||||||
count_collection_iterator_flat(&collection, Progress::None),
|
|
||||||
4
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -174,10 +145,6 @@ mod tests {
|
||||||
count_collection_for(&collection, progress_state),
|
count_collection_for(&collection, progress_state),
|
||||||
count_collection_iterator(&collection, progress_state),
|
count_collection_iterator(&collection, progress_state),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
|
||||||
count_collection_for(&collection, progress_state),
|
|
||||||
count_collection_iterator_flat(&collection, progress_state),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,6 @@ mod tests {
|
||||||
test: true,
|
test: true,
|
||||||
strict_clippy: true,
|
strict_clippy: true,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
skip_check_unsolved: false,
|
|
||||||
},
|
},
|
||||||
ExerciseInfo {
|
ExerciseInfo {
|
||||||
name: String::from("2"),
|
name: String::from("2"),
|
||||||
|
@ -119,7 +118,6 @@ mod tests {
|
||||||
test: false,
|
test: false,
|
||||||
strict_clippy: false,
|
strict_clippy: false,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
skip_check_unsolved: false,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue