Created
September 18, 2018 18:25
-
-
Save spektraldevelopment/284326862c2954496d0bc12c6b4a5194 to your computer and use it in GitHub Desktop.
JS: MaxChar
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
function maxChar(str) { | |
const charMap = {}; | |
let max = 0; | |
let maxChar = ''; | |
for(let char of str) { | |
charMap[char] = charMap[char] + 1 || 1; | |
} | |
for (let char in charMap) { | |
if (charMap[char] > max) { | |
max = charMap[char]; | |
maxChar = char; | |
} | |
} | |
return maxChar; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment