Skip to content

Instantly share code, notes, and snippets.

@relaxedtomato
Created March 24, 2015 13:28
Show Gist options
  • Save relaxedtomato/7d56a9a0a01d419063a2 to your computer and use it in GitHub Desktop.
Save relaxedtomato/7d56a9a0a01d419063a2 to your computer and use it in GitHub Desktop.
exercism.io wordcount
//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