Skip to content

Instantly share code, notes, and snippets.

@smallyunet
Created March 17, 2020 10:29
Show Gist options
  • Save smallyunet/079744874d1d31b94a9ffa5bd6f4470c to your computer and use it in GitHub Desktop.
Save smallyunet/079744874d1d31b94a9ffa5bd6f4470c to your computer and use it in GitHub Desktop.
get character total number by ...
/**
* @param Array
* @return Map
*/
var getCharNumByArray = (arr) => {
var m = new Map()
arr.map(i => {
if (m.get(i) == undefined) {
m.set(i, 1)
} else {
m.set(i, m.get(i)+1)
}
})
return m
}
/**
* @param String
* @return Map
*/
var getCharNumByString = (str) => {
var m = new Map()
str.split('').map(i => {
if (m.get(i) == undefined) {
m.set(i, 1)
} else {
m.set(i, m.get(i)+1)
}
})
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment