Skip to content

Commit

Permalink
iterators5
Browse files Browse the repository at this point in the history
  • Loading branch information
vhuynhle committed Aug 27, 2023
1 parent 8ba302f commit dd9dd8f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions exercises/iterators/iterators5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// Execute `rustlings hint iterators5` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

use std::collections::HashMap;

#[derive(Clone, Copy, PartialEq, Eq)]
Expand All @@ -35,7 +33,7 @@ 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.values().filter(|&&v| v == value).count()
}

fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
Expand All @@ -54,7 +52,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))
.fold(0, |x, y| x + y)
}

#[cfg(test)]
Expand Down

0 comments on commit dd9dd8f

Please sign in to comment.