Skip to content

Commit

Permalink
Merge pull request #16 from node-monk/patch-1
Browse files Browse the repository at this point in the history
Fix for "Cannot read property 'length' of null"
  • Loading branch information
waseem18 authored Oct 30, 2017
2 parents ac8899e + 52e812d commit 8d988dc
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ class Rake {
const wordScore = {};
phraseList.forEach((phrase) => {
const wordList = phrase.match(/[,.!?;:/‘’“”]|\b[0-9a-z']+\b/gi);
const wordListDegree = wordList.length;
wordList.forEach((word) => {
if (wordFreq[word]) {
wordFreq[word] += 1;
}
else {
wordFreq[word] = 1;
}
if (wordDegree[word]) {
wordDegree[word] += wordListDegree;
}
else {
wordDegree[word] = wordListDegree;
}
});
if(wordList){
const wordListDegree = wordList.length;
wordList.forEach((word) => {
if (wordFreq[word]) {
wordFreq[word] += 1;
}
else {
wordFreq[word] = 1;
}
if (wordDegree[word]) {
wordDegree[word] += wordListDegree;
}
else {
wordDegree[word] = wordListDegree;
}
});
}
});

Object.values(wordFreq).forEach((freq) => { wordDegree[freq] += wordFreq[freq]; });
Expand Down

0 comments on commit 8d988dc

Please sign in to comment.