Skip to content

Instantly share code, notes, and snippets.

@aire-con-gas
Created April 12, 2018 12:35
Show Gist options
  • Select an option

  • Save aire-con-gas/34e5e8d40a67f60fdcee4ba731c5b2d5 to your computer and use it in GitHub Desktop.

Select an option

Save aire-con-gas/34e5e8d40a67f60fdcee4ba731c5b2d5 to your computer and use it in GitHub Desktop.
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