-
Notifications
You must be signed in to change notification settings - Fork 10k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please help to solve iterators5.rs #812
Comments
For the function inside |
Alternatively, use map
.values()
.filter(|v| *v == &value)
.count() Note that in collection
.iter()
.map(|map| count_iterator(map, value))
.sum() |
The Rustlings' hint is to use But... thinking of using And I would point to |
from the hint:
|
For the fold approach you can think of something like that: fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
collection.iter().fold(0, |acc, x| acc count_iterator(x, value))
} |
Both using fold: 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, ... }
map.iter().fold(0, |acc, cur| if cur.1 == &value { return acc 1 } else { acc })
} fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
// collection is a slice of hashmaps.
// collection = [{ "variables1": Complete, "from_str": None, ... },
// { "variables2": Complete, ... }, ... ]
collection.iter().fold(0, |acc, map| acc count_iterator(map, value))
} |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi stuck on this exercises could someone please help to solve it
The text was updated successfully, but these errors were encountered: