Created
April 12, 2018 12:35
-
-
Save aire-con-gas/34e5e8d40a67f60fdcee4ba731c5b2d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var myWordMap = {}; | |
| function generateWordMap(arg) { | |
| // var wordMap = {}; | |
| var blacklistedWords = ['after', 'the', 'and', 'then']; | |
| var wordArr = arg.replace(/[.,:]/g, '').split(' '); | |
| var word; | |
| for(var i = 0, il = wordArr.length; i < il; i++) { | |
| word = wordArr[i].toLowerCase(); | |
| if (!blacklistedWords.includes(word)) { | |
| myWordMap[word] = (myWordMap[word] || 0) + 1; | |
| } | |
| }; | |
| } | |
| console.log(generateWordMap('After beating the eggs, Dana read the next step:')); | |
| console.log(generateWordMap('Add milk and eggs, then add flour and sugar.')); | |
| console.log(myWordMap); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment