Skip to content

Instantly share code, notes, and snippets.

@alexbrillant
Created September 27, 2017 18:51
Show Gist options
  • Save alexbrillant/03dd9c68f7cfe91ab93da1a841481f4c to your computer and use it in GitHub Desktop.
Save alexbrillant/03dd9c68f7cfe91ab93da1a841481f4c to your computer and use it in GitHub Desktop.
export function occurenceOfCharacters (string) {
const map = new Map()
for (let i = 0; i < string.length; i++) {
const char = string[i]
if (!map.get(char)) {
map.set(char, 1)
} else {
const currentCount = map.get(char)
map.set(char, currentCount + 1)
}
}
return map
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment