refac(rust): use hashmap entry for in-place manipulation

This commit is contained in:
Dmitriy Pleshevskiy 2021-10-29 11:12:45 +03:00
parent 2adc74168d
commit 7c6d9ae21d

View file

@ -4,7 +4,7 @@ fn count_duplicates(text: &str) -> u32 {
text.to_lowercase() text.to_lowercase()
.chars() .chars()
.fold(HashMap::<char, u32>::new(), |mut hm, c| { .fold(HashMap::<char, u32>::new(), |mut hm, c| {
hm.insert(c, hm.get(&c).copied().unwrap_or_default() + 1); (*hm.entry(c).or_default()) += 1;
hm hm
}) })
.values() .values()