1111// Execute `rustlings hint iterators5` or use the `hint` watch subcommand for a
1212// hint.
1313
14- // I AM NOT DONE
15-
1614use std:: collections:: HashMap ;
1715
1816#[ derive( Clone , Copy , PartialEq , Eq ) ]
@@ -33,9 +31,7 @@ fn count_for(map: &HashMap<String, Progress>, value: Progress) -> usize {
3331}
3432
3533fn count_iterator ( map : & HashMap < String , Progress > , value : Progress ) -> usize {
36- // map is a hashmap with String keys and Progress values.
37- // map = { "variables1": Complete, "from_str": None, ... }
38- todo ! ( ) ;
34+ map. values ( ) . filter ( |& & v| v == value) . count ( )
3935}
4036
4137fn count_collection_for ( collection : & [ HashMap < String , Progress > ] , value : Progress ) -> usize {
@@ -51,10 +47,11 @@ fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progres
5147}
5248
5349fn count_collection_iterator ( collection : & [ HashMap < String , Progress > ] , value : Progress ) -> usize {
54- // collection is a slice of hashmaps.
55- // collection = [{ "variables1": Complete, "from_str": None, ... },
56- // { "variables2": Complete, ... }, ... ]
57- todo ! ( ) ;
50+ collection
51+ . iter ( )
52+ . flat_map ( |map| map. values ( ) )
53+ . filter ( |& & v| v == value)
54+ . count ( )
5855}
5956
6057#[ cfg( test) ]
0 commit comments