Current Progress: 92/94
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// iterators4.rs
|
||||
// Execute `rustlings hint iterators4` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
pub fn factorial(num: u64) -> u64 {
|
||||
// Complete this function to return the factorial of num
|
||||
@@ -13,7 +12,7 @@ pub fn factorial(num: u64) -> u64 {
|
||||
// For an extra challenge, don't use:
|
||||
// - recursion
|
||||
// Execute `rustlings hint iterators4` for hints.
|
||||
vec![1..num].iter().rfold(1, |acc, x| acc + x)
|
||||
(1..=num).rfold(1, |acc, x| acc * x)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
//
|
||||
// Make the code compile and the tests pass.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -34,7 +33,10 @@ fn count_for(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
||||
fn count_iterator(map: &HashMap<String, Progress>, value: Progress) -> usize {
|
||||
// map is a hashmap with String keys and Progress values.
|
||||
// map = { "variables1": Complete, "from_str": None, ... }
|
||||
todo!();
|
||||
map
|
||||
.iter()
|
||||
.filter(|x| *x.1 == value)
|
||||
.count()
|
||||
}
|
||||
|
||||
fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
|
||||
@@ -53,7 +55,10 @@ fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Pr
|
||||
// collection is a slice of hashmaps.
|
||||
// collection = [{ "variables1": Complete, "from_str": None, ... },
|
||||
// { "variables2": Complete, ... }, ... ]
|
||||
todo!();
|
||||
collection
|
||||
.iter()
|
||||
.map(|map| count_iterator(map, value))
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user