Skip to content

Instantly share code, notes, and snippets.

@ckahle33
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save ckahle33/74f12a96699faf33b32b to your computer and use it in GitHub Desktop.

Select an option

Save ckahle33/74f12a96699faf33b32b to your computer and use it in GitHub Desktop.
Store number of char occurrences in a string
function countLetters(string) {
var splitString = string.split('');
var store = {};
splitString.forEach(function(val, index){
if (val in store && val !== ' ') {
store[val]++;
} else {
store[val] = 1;
}
})
console.log(store);
}
countLetters("hello, here is a string");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment