Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let words = ['cat','dog','mouse','rabbit','dog','dog','mouse','cat'];
let wordsSet = new Set(words)
let wordMap = new Map();
for(word in words){
let current = words[word];
if (wordMap.has(current)){
//is in the map, so get the current value and increment by one
let currentVal = wordMap.get(current);
currentVal++;
//update the value in the map
wordMap.set(current, currentVal);
}
else{
//not in the map, set its value to 1
wordMap.set(current,1)
}
}
//test to see if the size of the map is the same as the size of the set
let sameSizeTest = wordMap.size == wordsSet.size;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment