Created
March 17, 2020 10:29
-
-
Save smallyunet/079744874d1d31b94a9ffa5bd6f4470c to your computer and use it in GitHub Desktop.
get character total number by ...
This file contains 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
/** | |
* @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