Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Count letters in a string - returns an object with character for key and the character count for value
function countLetters (string) {
let letters = {};
for (let i = 0; i < string.length; i++) {
letters[string[i]] = letters[string[i]] + 1 || 1;
return letters;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.