Created
March 24, 2015 13:28
-
-
Save relaxedtomato/7d56a9a0a01d419063a2 to your computer and use it in GitHub Desktop.
exercism.io wordcount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//store each word as object key, and property count | |
//this allows for quick lookup and counting | |
var words = function(str){ | |
var strArr = str.split(" "); | |
var objCount = {}; | |
strArr.forEach(function(word){ | |
if(objCount[word]){ | |
objCount[word] += 1; | |
}else{ | |
objCount[word] = 1; | |
} | |
}); | |
console.log(objCount); | |
return objCount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment