Step 3: Identifying Duplicate Words
What are Duplicate Words?
Duplicate words are the keys in our HashMap with a value greater than 1, as these words have appeared more than once in the sentence.
How to Find Them?
We can loop through our occurrences
HashMap to find these duplicates.
1let duplicates = [];
2for(let [word, count] of Object.entries(occurrences)) {
3 if(count > 1) {
4 duplicates.push(word);
5 }
6}