From 761380d5bc75a89daf76923e614b9bfee65edf82 Mon Sep 17 00:00:00 2001 From: Irvin Zhan Date: Mon, 7 Sep 2015 14:23:07 -0400 Subject: [PATCH] fix word count Fixes incorrect word count. The current implementation adds a period to the end of any text, which adds an extra word count to any phrase. Taking an example from https://github.com/cgiffard/TextStatistics.js/issues/4 for instance: ``` var stats = textstatistics("monkey goes yay"); stats.wordCount(); 4 ``` --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e2c1059..5ee0f20 100644 --- a/index.js +++ b/index.js @@ -84,7 +84,8 @@ TextStatistics.prototype.wordCount = function(text) { text = text ? cleanText(text) : this.text; - return text.split(/[^a-z0-9]+/i).length || 1; + matches = text.match(/[\d\w]+/ig); + return matches ? matches.length : 0; }; TextStatistics.prototype.averageWordsPerSentence = function(text) {