diff --git a/word-count.js b/word-count.js index 4696535..ad60d56 100644 --- a/word-count.js +++ b/word-count.js @@ -9,9 +9,15 @@ function Words() {}; Words.prototype.count = function (input) { -// -// YOUR CODE GOES HERE -// + 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;