last iter

This commit is contained in:
Tirth Patel 2024-04-12 13:07:16 -02:30
parent 2356a8d73b
commit 71a17b5616

View File

@ -11,7 +11,6 @@
// Execute `rustlings hint iterators5` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
use std::collections::HashMap;
@ -35,7 +34,13 @@ 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().fold(0 as usize, |acc, x| {
if *x.1 == value
{
return acc+1
}
acc
})
}
fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
@ -54,7 +59,15 @@ 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().fold(0 as usize, |acc, map| {
acc + map.iter().fold(0 as usize, |inner_acc, val| {
if *val.1 == value
{
return inner_acc + 1
}
inner_acc
})
})
}
#[cfg(test)]