Current Progress: 92/94

This commit is contained in:
2023-06-15 17:30:11 -05:00
parent 1230b6cdb2
commit 05f28181d0
21 changed files with 80 additions and 699 deletions
+1 -2
View File
@@ -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)]
+8 -3
View File
@@ -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)]