Skip to content

Instantly share code, notes, and snippets.

@jordancalder
Last active September 1, 2016 05:49
Show Gist options
  • Save jordancalder/9fb30f42b9ab06f2cc6aa1c4434e0a01 to your computer and use it in GitHub Desktop.
Save jordancalder/9fb30f42b9ab06f2cc6aa1c4434e0a01 to your computer and use it in GitHub Desktop.
CareerBuilder - Question 2 (Char Count)
/*
Given a string, return the character count for each distinct character in the string.
· Example: "abacca" -> a: 3, b: 1, c: 2
· Once again, do not assume that “abacca” is the only string it will handle
*/
const charCount = (s) => {
return s.split('').reduce((chars, a) => {
chars[a] = (chars[a] || 0) + 1;
return chars;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment