Skip to content

Instantly share code, notes, and snippets.

@buymed-hoangpham
Last active September 25, 2022 08:52
Show Gist options
  • Save buymed-hoangpham/7d29eb64057fd46a943f03dc345253f3 to your computer and use it in GitHub Desktop.
Save buymed-hoangpham/7d29eb64057fd46a943f03dc345253f3 to your computer and use it in GitHub Desktop.
const countCharacters = (str) => {
const result = {};
const arr = str.split('');
for (word of arr) {
if (result[word]) {
result[word]++;
} else {
result[word] = 1;
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment