Skip to content

Instantly share code, notes, and snippets.

@bee-san
Last active August 27, 2018 13:12
Show Gist options
  • Select an option

  • Save bee-san/eb5ac1d1dbea19b043d863855930a7a1 to your computer and use it in GitHub Desktop.

Select an option

Save bee-san/eb5ac1d1dbea19b043d863855930a7a1 to your computer and use it in GitHub Desktop.
function countWords(words){
// returns a dictionary of {WORD: COUNT} where count is
// how many times that word appears in "words".
const unique_words = uniqueWords(words);
let dict = {};
// for every single unique word
for (let i = 0; i <= unique_words.length - 1; i++){
dict[unique_words[i]] = 0
// see how many times this unique word appears in all words
for (let x = 0; x <= words_without_stopwords.length -1; x++){
if (unique_words[i] == words[x]){
dict[unique_words[i]] = dict[unique_words[i]] + 1;
}
}
}
return dict;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment