Last active
September 1, 2016 05:49
-
-
Save jordancalder/9fb30f42b9ab06f2cc6aa1c4434e0a01 to your computer and use it in GitHub Desktop.
CareerBuilder - Question 2 (Char Count)
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
/* | |
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