From 662da7f8284146015fe66fb99c49092a3cea5c8a Mon Sep 17 00:00:00 2001 From: Adam Sakhr Date: Mon, 25 Apr 2016 13:24:12 +0200 Subject: [PATCH 1/2] First Check --- word-count.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/word-count.js b/word-count.js index 4696535..6128874 100644 --- a/word-count.js +++ b/word-count.js @@ -9,9 +9,9 @@ function Words() {}; Words.prototype.count = function (input) { -// -// YOUR CODE GOES HERE -// +var words = function( input ) { + return { word: 1 }; + } }; module.exports = Words; From ee6c8ede5987227e5b162e651dce887682cc90fd Mon Sep 17 00:00:00 2001 From: Adam Sakhr Date: Mon, 25 Apr 2016 13:27:29 +0200 Subject: [PATCH 2/2] Second Check --- word-count.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/word-count.js b/word-count.js index 6128874..ad60d56 100644 --- a/word-count.js +++ b/word-count.js @@ -9,9 +9,15 @@ function Words() {}; Words.prototype.count = function (input) { -var words = function( input ) { - return { word: 1 }; - } + var counts = {}; + var words = input.match(/\S+/g); + + words.forEach(function (word) { + var lcWord = word.toLowerCase(); + counts[lcWord] = counts.hasOwnProperty(lcWord) ? counts[lcWord] + 1 : 1; + }); + + return counts; }; module.exports = Words;