Skip to content

Use "key" instead of "value" in HashMap exercise #2763

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/std-types/exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ impl Counter {
}
}

/// Count an occurrence of the given value.
fn count(&mut self, value: u32) {
if self.values.contains_key(&value) {
*self.values.get_mut(&value).unwrap() += 1;
/// Count an occurrence of the given key.
fn count(&mut self, key: u32) {
if self.values.contains_key(&key) {
*self.values.get_mut(&key).unwrap() += 1;
} else {
self.values.insert(value, 1);
self.values.insert(key, 1);
}
}

/// Return the number of times the given value has been seen.
fn times_seen(&self, value: u32) -> u64 {
self.values.get(&value).copied().unwrap_or_default()
/// Return the number of times the given key has been seen.
fn times_seen(&self, key: u32) -> u64 {
self.values.get(&key).copied().unwrap_or_default()
}
}

Expand Down