This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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