Last active
August 29, 2015 14:24
-
-
Save ckahle33/74f12a96699faf33b32b to your computer and use it in GitHub Desktop.
Store number of char occurrences in a string
This file contains hidden or 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
| 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